blob: 7d57e30538371eda229710b3d6e81e0d5966bbc2 [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:
39 Value thisRef;
40 std::string methodName;
41 int methodDispatchId;
42 int numArgs;
43 const Value* args;
44
45protected:
46 /**
47 * @param args array of arguments -- InvokeMessage takes ownership and will
48 * destroy when it is destroyed.
49 */
50 InvokeMessage(const Value& thisRef, const std::string& methodName,
51 int numArgs, const Value* args) : thisRef(thisRef), methodName(methodName),
52 numArgs(numArgs), args(args) {}
53
54public:
55 ~InvokeMessage();
56 virtual char getType() const;
57
58 Value getThis() const { return thisRef; }
59 const std::string& getMethodName() const { return methodName; }
60 int getNumArgs() const { return numArgs; }
61 const Value* const getArgs() const { return args; }
62
63 static InvokeMessage* receive(HostChannel& channel);
64 static bool send(HostChannel& channel, const Value& thisRef, int methodDispatchId,
65 int numArgs, const Value* args);
66};
67#endif