2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_IpcClient.h
19 * @brief This is the header file for the _IpcClient class.
21 * This file contains the declarations of _IpcClient.
25 #ifndef _FIO_INTERNAL_IPC_CLIENT_H_
26 #define _FIO_INTERNAL_IPC_CLIENT_H_
32 #include <ipc/ipc_message_macros.h>
33 #include <ipc/ipc_message_utils.h>
35 #include <FBaseResult.h>
36 #include <FBaseObject.h>
37 #include <FBaseString.h>
38 #include <FOspConfig.h>
41 namespace Tizen { namespace Base { namespace Runtime
45 namespace Tizen { namespace Io
48 class _IIpcClientEventListener;
52 * @brief This class provides methods for sending a message to an IPC server.
55 class _OSP_EXPORT_ _IpcClient
61 virtual ~_IpcClient(void);
64 * Constructs the instance of this class.
66 * @return An error code
67 * @param[in] serverName The name of the server
68 * @param[in] pListener Set if the client want to handle a message from the IPC server.
70 * @exception E_SUCCESS The method was successful.
71 * @exception E_OBJ_NOT_FOUND The IPC server was not found.
72 * @exception E_OUT_OF_MEMORY Insufficient memory.
73 * @exception E_SYSTEM A system error occurred.
75 result Construct(const Tizen::Base::String& serverName, const _IIpcClientEventListener* pListener = null);
78 * Returns the name of the IPC server.
80 * @return The name of the IPC server.
82 Tizen::Base::String GetName(void) const;
85 * Sends a request message to an IPC server.
90 * CalculatorProxy::Add(int a , int b)
94 * My_sum mySum(a, b, &c);
96 * __pIpcClient->SendRequest(mySum);
102 * @return An error code
103 * @param[in] message The message to send
104 * @exception E_SUCCESS The method was successful.
105 * @exception E_INVALID_STATE The instance is in an invalid state.
106 * @exception E_OUT_OF_MEMORY Insufficient memory.
107 * @exception E_TIMEOUT The operation can not be completed within the specified time period.
108 * @exception E_SYSTEM A system error occurred.
111 result SendRequest(const IPC::Message& message);
113 result SendRequest(IPC::Message* pMessage);
117 * Sets the timeout value which is used to send a synchronous message to the server.
119 * @param[in] timeout The time limit for synchronous messages, in milliseconds.
120 * @c infinite timeout if @c timeout value is a negative.
122 void SetTimeout(int timeout);
125 * Gets the timeout value.
127 * @return The name of the IPC server.
129 int GetTimeout() const;
132 _IpcClient(const _IpcClient& value);
134 _IpcClient& operator =(const _IpcClient& value);
136 result Send(IPC::Message* pMessage);
138 result SendAsync(IPC::Message* pMessage);
140 result SendSync(IPC::Message* pMessage);
142 result MakeConnection(bool forReverse = false);
146 void ReleaseFd(int fd);
148 static gboolean OnReadMessage(GIOChannel* source, GIOCondition condition, gpointer data);
150 gboolean HandleReceivedMessage(GIOChannel* source, GIOCondition condition);
153 GSource* __pReverseSource;
155 std::vector <int> __fds;
158 Tizen::Base::Runtime::Mutex* __pFdLock;
159 Tizen::Base::String __name;
160 _IIpcClientEventListener* __pListener;
162 static const int __MAX_MESSAGE_BUFFER_SIZE = 1024;
163 char __messageBuffer[__MAX_MESSAGE_BUFFER_SIZE];
164 std::string __pending;
169 #endif // _FIO_INTERNAL_IPC_CLIENT_H_