jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 1 | #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 | |
| 24 | class 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 | */ |
| 34 | class InvokeMessage : public Message { |
| 35 | public: |
| 36 | static const char TYPE = MESSAGE_TYPE_INVOKE; |
| 37 | static const int TOSTRING_DISP_ID = 0; |
| 38 | private: |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 39 | gwt::Value thisRef; |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 40 | std::string methodName; |
| 41 | int methodDispatchId; |
| 42 | int numArgs; |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 43 | const gwt::Value* args; |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 44 | |
| 45 | protected: |
| 46 | /** |
| 47 | * @param args array of arguments -- InvokeMessage takes ownership and will |
| 48 | * destroy when it is destroyed. |
| 49 | */ |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 50 | InvokeMessage(const gwt::Value& thisRef, const std::string& methodName, |
| 51 | int numArgs, const gwt::Value* args) : thisRef(thisRef), methodName(methodName), |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 52 | numArgs(numArgs), args(args) {} |
| 53 | |
| 54 | public: |
| 55 | ~InvokeMessage(); |
| 56 | virtual char getType() const; |
| 57 | |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 58 | gwt::Value getThis() const { return thisRef; } |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 59 | const std::string& getMethodName() const { return methodName; } |
| 60 | int getNumArgs() const { return numArgs; } |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 61 | const gwt::Value* const getArgs() const { return args; } |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 62 | |
| 63 | static InvokeMessage* receive(HostChannel& channel); |
acleung@google.com | cd201b7 | 2012-01-24 16:23:41 +0000 | [diff] [blame] | 64 | static bool send(HostChannel& channel, const gwt::Value& thisRef, int methodDispatchId, |
| 65 | int numArgs, const gwt::Value* args); |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 66 | }; |
| 67 | #endif |