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.
19 * @file FIo_IpcClient.h
20 * @brief This is the header file for the _IpcClient class.
22 * This file contains the declarations of _IpcClient.
26 #ifndef _FIO_INTERNAL_IPC_CLIENT_H_
27 #define _FIO_INTERNAL_IPC_CLIENT_H_
33 #include <ipc/ipc_message_macros.h>
34 #include <ipc/ipc_message_utils.h>
36 #include <FBaseResult.h>
37 #include <FBaseObject.h>
38 #include <FBaseString.h>
39 #include <FOspConfig.h>
42 namespace Tizen { namespace Base { namespace Runtime
46 namespace Tizen { namespace Io
49 class _IIpcClientEventListener;
53 * @brief This class provides methods for sending a message to an IPC server.
56 class _OSP_EXPORT_ _IpcClient
62 virtual ~_IpcClient(void);
65 * Constructs the instance of this class.
67 * @return An error code
68 * @param[in] serverName The name of the server
69 * @param[in] pListener Set if the client want to handle a message from the IPC server.
71 * @exception E_SUCCESS The method was successful.
72 * @exception E_OBJ_NOT_FOUND The IPC server was not found.
73 * @exception E_OUT_OF_MEMORY Insufficient memory.
74 * @exception E_SYSTEM A system error occurred.
76 result Construct(const Tizen::Base::String& serverName, const _IIpcClientEventListener* pListener = null);
79 * Sends a request message to an IPC server.
84 * CalculatorProxy::Add(int a , int b)
88 * My_sum mySum(a, b, &c);
90 * __pIpcClient->SendRequest(mySum);
96 * @return An error code
97 * @param[in] message The message to send
98 * @exception E_SUCCESS The method was successful.
99 * @exception E_INVALID_STATE The instance is in an invalid state.
100 * @exception E_OUT_OF_MEMORY Insufficient memory.
101 * @exception E_SYSTEM A system error occurred.
104 result SendRequest(const IPC::Message& message);
106 result SendRequest(IPC::Message* pMessage);
109 _IpcClient(const _IpcClient& value);
111 _IpcClient& operator =(const _IpcClient& value);
113 result Send(IPC::Message* pMessage);
115 result SendAsync(IPC::Message* pMessage);
117 result SendSync(IPC::Message* pMessage);
119 result MakeConnection(bool forReverse = false);
123 void ReleaseFd(int fd);
125 static gboolean OnReadMessage(GIOChannel* source, GIOCondition condition, gpointer data);
127 gboolean HandleReceivedMessage(GIOChannel* source, GIOCondition condition);
130 GSource* __pReverseSource;
132 std::vector <int> __fds;
134 Tizen::Base::Runtime::Mutex* __pFdLock;
135 Tizen::Base::String __name;
136 _IIpcClientEventListener* __pListener;
138 static const int __MAX_MESSAGE_BUFFER_SIZE = 1024;
139 char __messageBuffer[__MAX_MESSAGE_BUFFER_SIZE];
140 std::string __pending;
145 #endif // _FIO_INTERNAL_IPC_CLIENT_H_