2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 rpc_internal.h
19 * @brief RPC Library Internal Implementation-Type, macro, and function definitions used internally
22 /** @addtogroup RPClib_in
24 #ifndef OTHERSERVICE_RPCINTERNAL_H_ // NOLINT(build/header_guard)
25 #define OTHERSERVICE_RPCINTERNAL_H_ // NOLINT(build/header_guard)
30 #if defined(__linux__)
31 /* Using unix autobind Features That Are Only Available in linux */
32 #define RPC_USE_UNIX_AUTOBIND
33 #endif /* __linux__ */
35 #define RPC_USE_SYSLOG
37 typedef RPC_ID *RPC_ID_p;
40 #include "rpc_thread.h"
42 RPC_Result RpcQueueAPIRequestBefore(RpcIdInfo *id,
43 UINT32 size, char **buff);
44 RPC_Result RpcQueueAPIRequestAfter(RpcIdInfo *id, RPC_ID client,
45 const char *mesg, UINT32 size,
47 void RpcFreeAPIArgsString(char *args_string);
48 UINT16 RpcGetAPIRequest(RpcIdInfo *id, RPC_ID_p client,
49 char **args_string, unsigned int *args_size);
50 RPC_Result RpcSetAPIcallReturn(RpcIdInfo *id,
51 const char *mesg, UINT32 size);
52 void RpcDiscardAPIcallReturn(RpcIdInfo *id);
54 RPC_Result RpcDeleteSrvrPid(RpcIdInfo *idinfo, RPC_ID srvr_rpc_id, int wd);
56 #define StrEqual(a, b) (strcmp((a), (b)) == 0)
57 #define MemEqual(a, b, c) (memcmp((a), (b), (c)) == 0)
59 #define RPC_IS_INVALID_ID(a) ((a) == RPC_NO_ID)
60 #define RPC_INVALIDATE_ID(a) ((a) = RPC_NO_ID)
61 #define RPC_ID_COPY(a, b) ((a) = (b))
62 #define RPC_ID_Equal(a, b) ((a) == (b))
64 /* inotify Events read Sizes */
65 #define EVENT_SIZE ( sizeof(struct inotify_event) ) /* One inotify event size */
66 #define BUF_LEN (4 * EVENT_SIZE) /* Read sizes */
70 #define SET_NONBLOCK(fd) { \
72 flag = fcntl((fd), F_GETFL, 0); \
73 fcntl((fd), F_SETFL, O_NONBLOCK|flag); \
76 #define SET_CLOSE_ON_EXEC(fd) { \
78 flag = fcntl((fd), F_GETFD, 0); \
79 fcntl((fd), F_SETFD, FD_CLOEXEC|flag); \
82 #if defined(RPC_USE_SYSLOG)
86 #define RPC_LOG_CRIT(format, arg...) syslog(LOG_CRIT, format "\n", ##arg)
87 #define RPC_LOG_ERR(format, arg...) syslog(LOG_ERR, format "\n", ##arg)
88 #define RPC_LOG_STATE(format, arg...) syslog(LOG_INFO, format "\n", ##arg)
89 #define RPC_LOG_DEBUG(format, arg...) syslog(LOG_DEBUG, format "\n", ##arg)
91 #else // defined(RPC_USE_SYSLOG)
93 #define RPC_LOG_CRIT(format, arg...) fprintf(stderr, "[RPC:CRIT](%d): " format "\n", getpid(), ##arg)
94 #define RPC_LOG_ERR(format, arg...) fprintf(stderr, "[RPC:ERR](%d): " format "\n", getpid(), ##arg)
95 #define RPC_LOG_STATE(format, arg...) fprintf(stderr, "[RPC:STATE](%d): " format "\n", getpid(), ##arg)
96 #define RPC_LOG_DEBUG(format, arg...)
98 #endif // defined(RPC_USE_SYSLOG)
100 #include <sys/prctl.h>
102 #define RPC_LOG_ERR_W_NAME(format, arg...) \
105 prctl(PR_GET_NAME, name); \
107 RPC_LOG_ERR("(%s): " format, name, ##arg); \
110 #define RPC_LOG_PERROR(format, arg...) RPC_LOG_ERR("[%s:%d] %s : " format, __FILE__, __LINE__, strerror(errno), ##arg);
113 #define rpc_assert assert
115 #define BUG_ASSERT(cond, x) \
117 rpc_assert("BUG ASSERTION! " #x " @ " __FILE__ ==NULL); \
119 #define CONFIG_ASSERT(s) rpc_assert((s) == NULL)
121 #define RUNS_IN_CALLERS_THREAD
122 #define RUNS_IN_READING_THREAD
124 #if !defined(RPC_USE_UNIX_AUTOBIND)
126 #define RPC_SOCKET_NAME "/tmp/RPC/%05d"
129 rpc_set_socket_name(char *str, RPC_ID id) {
130 sprintf(str, RPC_SOCKET_NAME, id); // NOLINT (readability/nolint)
133 #endif /* !AUTOBIND */
135 #endif // OTHERSERVICE_RPCINTERNAL_H_