1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ****************************************************************************/
20 #ifndef _DBUSMESSAGEHANDLER_H_
21 #define _DBUSMESSAGEHANDLER_H_
25 using std::stringstream;
31 #include <dbus/dbus.h>
33 #define DLT_CONTEXT DBusCommandPlugin
35 typedef void (CommandDbusReceive::*CallBackMethod)(DBusConnection *connection, DBusMessage *message);
40 const char *signature;
42 CallBackMethod function;
47 const char* signature;
51 class DBUSMessageHandler
54 DBUSMessageHandler(DBusObjectPathVTable* vtable, DBusConnection* conn, void* reference);
55 ~DBUSMessageHandler();
57 void initReceive(DBusMessage* msg);
58 void initReply(DBusMessage* msg);
60 void ReplyError(DBusMessage* msg, const char* errorname, const char* errorMsg);
62 dbus_uint32_t getUInt();
64 dbus_bool_t getBool();
67 void getArrayOfUInt(int* length, unsigned int** array);
68 void getArrayOfString(std::vector<std::string>* uniforms);
70 void append(dbus_uint32_t toAppend);
71 void append(char toAppend);
72 void append(bool toAppend);
73 void append(double toAppend);
74 void append(unsigned int length, unsigned int *IDs);
75 void append(std::list<SourceType> list);
76 void append(std::list<ConnectionType> list);
77 void append(std::list<SinkType> list);
79 void sendSignal(const char* signalname);
82 DBusMessageIter m_MessageIter;
83 DBusMessage* m_pReply;
84 dbus_uint32_t m_serial;
85 DBusConnection* m_pConnection;
89 class DBUSIntrospection
92 DBUSIntrospection(MethodTable* table, SignalTable* stable,std::string nodename);
93 void process(DBusConnection* conn, DBusMessage* msg);
96 void generateString(void);
99 void addArgument(string argname, string direction, string type);
100 void addSignalArgument(string argname, string type);
101 void addEntry(MethodTable entry);
102 void addEntry(SignalTable entry);
104 void openNode(string nodename);
105 void closeNode(void);
107 void openInterface(string interfacename);
108 void closeInterface(void);
110 void openMethod(string methodname);
111 void closeMethod(void);
113 void openSignal(string signalname);
114 void closeSignal(void);
117 stringstream m_introspectionString;
118 MethodTable* m_methodTable;
119 SignalTable* m_signalTable;
120 std::string m_nodename;
123 #endif // _DBUSMESSAGEWRAPPER_H_