blob: 0296d7591a2a79d159e4dd0b4f034f634e502e29 [file] [log] [blame]
jat@google.com134be542009-08-03 15:30:11 +00001#ifndef __INVOKEMESSAGE_H
2#define __INVOKEMESSAGE_H
3/*
4 * Copyright 2008 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <string>
20#include "Message.h"
21#include "BrowserChannel.h"
22#include "Value.h"
23
24class HostChannel;
25
26/**
27 * Class representing an InvokeMessage received from the server, and a way
28 * to send an invoke message to the server.
29 *
30 * Note that the wire protocol is different in the two directions, as the
31 * server sends a string for the method name and the client send an integer
32 * dispatchID.
33 */
34class InvokeMessage : public Message {
35public:
36 static const char TYPE = MESSAGE_TYPE_INVOKE;
37 static const int TOSTRING_DISP_ID = 0;
38private:
acleung@google.comcd201b72012-01-24 16:23:41 +000039 gwt::Value thisRef;
jat@google.com134be542009-08-03 15:30:11 +000040 std::string methodName;
41 int methodDispatchId;
42 int numArgs;
acleung@google.comcd201b72012-01-24 16:23:41 +000043 const gwt::Value* args;
jat@google.com134be542009-08-03 15:30:11 +000044
45protected:
46 /**
47 * @param args array of arguments -- InvokeMessage takes ownership and will
48 * destroy when it is destroyed.
49 */
acleung@google.comcd201b72012-01-24 16:23:41 +000050 InvokeMessage(const gwt::Value& thisRef, const std::string& methodName,
51 int numArgs, const gwt::Value* args) : thisRef(thisRef), methodName(methodName),
jat@google.com134be542009-08-03 15:30:11 +000052 numArgs(numArgs), args(args) {}
53
54public:
55 ~InvokeMessage();
56 virtual char getType() const;
57
acleung@google.comcd201b72012-01-24 16:23:41 +000058 gwt::Value getThis() const { return thisRef; }
jat@google.com134be542009-08-03 15:30:11 +000059 const std::string& getMethodName() const { return methodName; }
60 int getNumArgs() const { return numArgs; }
acleung@google.comcd201b72012-01-24 16:23:41 +000061 const gwt::Value* const getArgs() const { return args; }
jat@google.com134be542009-08-03 15:30:11 +000062
63 static InvokeMessage* receive(HostChannel& channel);
acleung@google.comcd201b72012-01-24 16:23:41 +000064 static bool send(HostChannel& channel, const gwt::Value& thisRef, int methodDispatchId,
65 int numArgs, const gwt::Value* args);
jat@google.com134be542009-08-03 15:30:11 +000066};
67#endif