2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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.
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);
76 bool wait_for_reply();
78 int sockfd, remotefd, maxfd;
83 class MsgIpcServerSocket
87 ~MsgIpcServerSocket() { mapFds.clear(); }
88 int maxFd() { return (maxfd+1); }
89 fd_set fdSet() { return fds; }
90 int fd() { return sockfd; }
92 msg_error_t open(const char *path);
96 /* read msg from client of fd */
97 int read(int fd, char** buf, int* len);
98 /* write msg to ipc client */
99 int write(int fd, const char* buf, unsigned int len);
101 void setSockfd(int fd) { sockfd = fd; }
104 int readn(int fd, char *buf, unsigned int len);
105 int writen(int fd, const char *buf, unsigned int len);
107 /* server socket fd */
110 /* information about IPC clients, it is used for select() */
113 std::map<int, int> mapFds;
116 #endif /*__IPCSocket_H__ */