2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 #ifndef __IPCSocket_H__
18 #define __IPCSocket_H__
20 /*==================================================================================================
22 ==================================================================================================*/
23 #include <sys/types.h>
27 #include "MsgCppTypes.h"
30 /*==================================================================================================
32 ==================================================================================================*/
33 #define MSG_MAX_IPC_SIZE 50000 // 50 * 1000 = sizeof(msg common info) * max message count
34 #define MAX_NUM_IPC_CLIENT 10
36 #define MSG_SOCKET_PATH "/tmp/.msgfw_socket"
38 #define CUSTOM_SOCKET_ERROR -1
39 #define CUSTOM_SOCKET_BACKLOG 10
42 /*==================================================================================================
44 ==================================================================================================*/
47 CLOSE_CONNECTION_BY_SIGNAL = 0,
48 CLOSE_CONNECTION_BY_USER = -17,
52 /*==================================================================================================
54 ==================================================================================================*/
55 class MsgIpcClientSocket
59 // ~MsgIpcClientSocket();
61 int maxFd() { return (maxfd+1); }
62 fd_set fdSet() { return fds; }
63 int fd() { return sockfd; }
65 msg_error_t connect(const char *path);
67 /* write msg to ipc server */
68 int write(const char* buf, unsigned int len);
69 /* read msg from ipc server */
70 int read(char** buf, unsigned int* len);
72 int getRemoteFd() {return remotefd; }
74 int readn(char *buf, unsigned int len );
75 int writen (const char *buf, unsigned int len);
77 int sockfd, remotefd, maxfd;
82 class MsgIpcServerSocket
86 ~MsgIpcServerSocket() { mapFds.clear(); }
87 int maxFd() { return (maxfd+1); }
88 fd_set fdSet() { return fds; }
89 int fd() { return sockfd; }
91 msg_error_t open(const char *path);
95 /* read msg from client of fd */
96 int read(int fd, char** buf, int* len );
97 /* write msg to ipc client */
98 int write(int fd, const char* buf, unsigned int len);
100 void setSockfd(int fd) { sockfd = fd; }
103 int readn(int fd, char *buf, unsigned int len );
104 int writen (int fd, const char *buf, unsigned int len);
106 /* server socket fd */
109 /* information about IPC clients, it is used for select() */
112 std::map<int, int> mapFds;
115 #endif //__IPCSocket_H__