1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FILLP_OS_H
17 #define FILLP_OS_H
18 
19 #include "fillptypes.h"
20 #include "fillpcallbacks.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifndef FILLP_NUM_OF_EPOLL_INSTANCE_SUPPORTED
27 #define FILLP_NUM_OF_EPOLL_INSTANCE_SUPPORTED 10
28 #endif
29 
30 #define FILLP_INVALID_PTR(Ptr) (FILLP_NULL_PTR ==  (Ptr))
31 
32 #ifdef FILLP_LITTLE_ENDIAN
33 
34 #define FILLP_NTOHL(x) \
35     ((((x)&0x000000ff) << 24) | (((x)&0x0000ff00) << 8) | (((x)&0x00ff0000) >> 8) | (((x)&0xff000000) >> 24))
36 
37 #define FILLP_NTOHS(x) (FILLP_UINT16)((((x)&0x00ff) << 8) | (((x)&0xff00) >> 8))
38 
39 #define FILLP_NTOHLL(x)                                                                                              \
40     ((((x) >> 56) & 0x00000000000000FF) | (((x) >> 40) & 0x000000000000FF00) | (((x) >> 24) & 0x0000000000FF0000) |  \
41         (((x) >> 8) & 0x00000000FF000000) | (((x) << 8) & 0x000000FF00000000) | (((x) << 24) & 0x0000FF0000000000) | \
42         (((x) << 40) & 0x00FF000000000000) | (((x) << 56) & 0xFF00000000000000))
43 
44 
45 #define FILLP_HTONL(x) FILLP_NTOHL(x)
46 #define FILLP_HTONS(x) FILLP_NTOHS(x)
47 #define FILLP_HTONLL(x) FILLP_NTOHLL(x)
48 
49 #else
50 #define FILLP_NTOHL(x) (x)
51 #define FILLP_NTOHS(x) (x)
52 #define FILLP_HTONL(x) (x)
53 #define FILLP_HTONS(x) (x)
54 #define FILLP_HTONLL(x) (x)
55 #define FILLP_NTOHLL(x) (x)
56 #endif
57 
58 #define FILLP_ONE_SECOND 1000
59 #define FILLP_BPS_TO_KBPS 1000
60 #define FILLP_NULL_NUM 0x0
61 
62 #if defined(FILLP_LINUX)
63 #define FILLP_THREAD pthread_t
64 #ifndef unlikely
65 #define unlikely(x) __builtin_expect((x), 0)
66 #endif
67 #elif defined(FILLP_WIN32)
68 #define FILLP_THREAD unsigned int
69 #define unlikely(x) (x)
70 #else
71 #error "define systhread type and unlikely !!!"
72 #endif
73 
74 typedef struct FillpLmGlobalStruct {
75     FILLP_ULLONG logModules; /* Modules for which logs needs to enabled */
76     FILLP_UINT8 debugLevel;  /* dbg level : FillpDebugLevel */
77     FILLP_UINT8 funcTrace;   /* Open(1) and Close(0) function trc flag */
78     FILLP_BOOL mgtMsgLog;    /* Enable/Disable the management message log */
79 #ifdef FILLP_64BIT_ALIGN
80     FILLP_UINT8 padd;
81 #endif
82     FillpLmCallbackFunc lmCallbackFn;
83 } FillpLmGlobal;
84 
85 extern FillpSysLibBasicCallbackFuncSt g_fillpOsBasicLibFun;
86 extern FillpSysLibSemCallbackFuncSt g_fillpOsSemLibFun;
87 extern FillpSysLibSockCallbackFuncSt g_fillpOsSocketLibFun;
88 extern FillpAppCallbackFunc g_fillpAppCbkFun;
89 extern FillpLmGlobal g_fillpLmGlobal;
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif /* FILLP_OS_H */
96