dad6429412feb4333466f1d279226ebbed6a4af3
[profile/ivi/layer-management.git] / LayerManagerPlugins / Communicators / DBUSCommunicator / include / DBUSMessageHandler.h
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  *
5  *
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
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,
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.
17  *
18  ****************************************************************************/
19
20 #ifndef _DBUSMESSAGEHANDLER_H_
21 #define _DBUSMESSAGEHANDLER_H_
22
23 #include <vector>
24 #include <string>
25 #include <dbus/dbus.h>
26
27 class DBUSMessageHandler
28 {
29 public:
30     DBUSMessageHandler();
31     ~DBUSMessageHandler();
32
33     void setConnection(DBusConnection* conn);
34     DBusConnection* getConnection();
35
36     void initReceive(DBusMessage* msg);
37     bool registerPathFunction(  DBusObjectPathMessageFunction fMessageFunc, 
38                                 DBusObjectPathUnregisterFunction fUnregisterFunc,
39                                 void* comInstance);
40     void initReply(DBusMessage* msg);
41     void closeReply();
42     void ReplyError(DBusMessage* msg, const char* errorname, const char* errorMsg);
43     bool registerMessageFilter(  DBusHandleMessageFunction fMessageFunc,
44                                  void* comInstance );
45
46     dbus_uint32_t getUInt();
47     char getByte();
48     dbus_bool_t getBool();
49     double getDouble();
50     char* getString();
51     void getArrayOfUInt(int* length, unsigned int** array);
52     void getArrayOfString(std::vector<std::string>* uniforms);
53
54     void appendUInt(dbus_uint32_t toAppend);
55     void appendByte(char toAppend);
56     void appendBool(dbus_bool_t toAppend);
57     void appendDouble(double toAppend);
58     void appendArrayOfUInt(unsigned int length, unsigned int *IDs);
59
60 private:
61     DBusMessageIter m_MessageIter;
62     DBusMessage* m_pReply;
63     dbus_uint32_t m_serial;
64     DBusConnection* m_pConnection;
65     DBusError m_err;
66     DBusObjectPathVTable m_objectPathVTable;
67 };
68
69
70 inline void DBUSMessageHandler::setConnection(DBusConnection* conn)
71 {
72     m_pConnection = conn;
73 }
74
75 inline DBusConnection* DBUSMessageHandler::getConnection()
76 {
77     return m_pConnection;
78 }
79
80 #endif // _DBUSMESSAGEWRAPPER_H_