blob: 911cf3883479b35cbf8fca477a93cb41d58a963e [file] [log] [blame]
jat@google.com5e86cbd2009-08-22 23:59:24 +00001/*
2 * Copyright 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#include "CheckVersionsMessage.h"
18#include "HostChannel.h"
19#include "scoped_ptr/scoped_ptr.h"
20
21CheckVersionsMessage::~CheckVersionsMessage() {
22}
23
24char CheckVersionsMessage::getType() const {
25 return TYPE;
26}
27
28/**
29 * Receive a CheckVersions message from the channel (note that the message
30 * type has already been read). Caller is responsible for destroying
31 * returned message. Returns null on error.
32 */
33CheckVersionsMessage* CheckVersionsMessage::receive(HostChannel& channel) {
34 int minVersion;
35 if (!channel.readInt(minVersion)) {
36 // TODO(jat): error handling
37 printf("Failed to read minimum version\n");
38 return 0;
39 }
40 int maxVersion;
41 if (!channel.readInt(maxVersion)) {
42 // TODO(jat): error handling
43 printf("Failed to read maximum version\n");
44 return 0;
45 }
46 std::string hostedHtmlVersion;
47 if (!channel.readString(hostedHtmlVersion)) {
48 // TODO(jat): error handling
49 printf("Failed to read hosted.html version\n");
50 return 0;
51 }
52 return new CheckVersionsMessage(minVersion, maxVersion, hostedHtmlVersion);
53}
54
55/**
56 * Send a fatal error message on the channel.
57 */
58bool CheckVersionsMessage::send(HostChannel& channel, int minVersion,
59 int maxVersion, const std::string& hostedHtmlVersion) {
60 if (!channel.sendByte(TYPE)) return false;
61 if (!channel.sendInt(minVersion)) return false;
62 if (!channel.sendInt(maxVersion)) return false;
63 if (!channel.sendString(hostedHtmlVersion)) return false;
64 return true;
65}