2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the IpcClient class.
22 * This file contains the declarations of IpcClient.
26 #ifndef _IPC_CLIENT_H_
27 #define _IPC_CLIENT_H_
35 #include <ipc/ipc_message_macros.h>
36 #include <ipc/ipc_message_utils.h>
39 class IIpcClientEventListener;
43 * @brief This class provides methods for sending a message to an IPC server.
51 * This is the default constructor for this class.
56 * This is the destructor for this class.
58 virtual ~IpcClient(void);
61 * Constructs the instance of this class.
63 * @return An error code
64 * @param[in] serverName The name of the server
65 * @param[in] pListener Set if the client want to handle a message from the IPC server.
67 * @exception E_SUCCESS The method was successful.
68 * @exception E_OBJ_NOT_FOUND The IPC server was not found.
69 * @exception E_OUT_OF_MEMORY Insufficient memory.
70 * @exception E_SYSTEM A system error occurred.
72 int Construct(const std::string& serverName, const IIpcClientEventListener* pListener = NULL);
75 * Returns the name of the IPC server.
77 * @return The name of the IPC server.
79 std::string GetName(void) const;
82 * Sends a request message to an IPC server.
88 * CalculatorProxy::Add(int a , int b)
92 * My_sum mySum(a, b, &c);
94 * __pIpcClient->SendRequest(mySum);
100 * @return An error code
101 * @param[in] message The message to send
102 * @exception E_SUCCESS The method was successful.
103 * @exception E_INVALID_STATE The instance is in an invalid state.
104 * @exception E_OUT_OF_MEMORY Insufficient memory.
105 * @exception E_SYSTEM A system error occurred.
108 int SendRequest(const IPC::Message& message);
110 int SendRequest(IPC::Message* pMessage);
113 IpcClient(const IpcClient& value);
115 IpcClient& operator =(const IpcClient& value);
117 int Send(IPC::Message* pMessage);
119 int SendAsync(IPC::Message* pMessage);
121 int SendSync(IPC::Message* pMessage);
123 int MakeConnection(bool forReverse = false);
127 void ReleaseFd(int fd);
129 static gboolean OnReadMessage(GIOChannel* source, GIOCondition condition, gpointer data);
131 gboolean HandleReceivedMessage(GIOChannel* source, GIOCondition condition);
134 GSource* __pReverseSource;
135 pthread_mutex_t* __pMutex;
137 std::vector <int> __fds;
138 //Tizen::Base::Runtime::Mutex* __pFdLock;
141 IIpcClientEventListener* __pListener;
143 static const int __MAX_MESSAGE_BUFFER_SIZE = 1024;
144 char __messageBuffer[__MAX_MESSAGE_BUFFER_SIZE];
145 std::string __pending;
148 #endif // _IPC_CLIENT_H_