API for DTLS registration and Scon script addition
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caadapterutils.h
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file caadapterutils.h
23  * @brief This file contains common utility function for CA transport adaptors.
24  */
25
26 #ifndef _CA_ADAPTER_UTILS_H_
27 #define _CA_ADAPTER_UTILS_H_
28
29 #include <stdbool.h>
30
31 #include "cacommon.h"
32 #include "logger.h"
33 #include "oic_malloc.h"
34 #include "oic_string.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 /**
42  * @def VERIFY_NON_NULL
43  * @brief Macro to verify the validity of input argument
44  */
45 #define VERIFY_NON_NULL(arg, log_tag, log_message) \
46     if (NULL == arg ){ \
47         OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
48         return CA_STATUS_INVALID_PARAM; \
49     } \
50
51 /**
52  * @def VERIFY_NON_NULL_RET
53  * @brief Macro to verify the validity of input argument
54  */
55 #define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \
56     if (NULL == arg ){ \
57         OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
58         return ret; \
59     } \
60
61 /**
62  * @def VERIFY_NON_NULL_VOID
63  * @brief Macro to verify the validity of input argument
64  */
65 #define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
66     if (NULL == arg ){ \
67         OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
68         return; \
69     } \
70
71 /**
72  * @fn CAAdapterCreateLocalEndpoint
73  * @brief Create CALocalConnectivity_t instance.
74  */
75 CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CAConnectivityType_t type,
76         const char *address);
77
78 /**
79  * @fn CAAdapterCopyLocalEndpoint
80  * @brief Create CALocalConnectivity_t duplicate instance.
81  */
82 CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(CALocalConnectivity_t *connectivity);
83
84 /**
85  * @fn CAAdapterFreeLocalEndpoint
86  * @brief Deallocate CALocalConnectivity_t instance.
87  */
88 void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndPoint);
89
90 /**
91  * @fn CAAdapterCreateRemoteEndpoint
92  * @brief Allocate CARemoteEndpoint_t instance.
93  */
94 CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CAConnectivityType_t type,
95         const char *address, const char *resourceUri);
96
97 /**
98  * @fn CAAdapterCopyRemoteEndpoint
99  * @brief Create CARemoteEndpoint_t duplicate instance.
100  */
101 CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(
102     const CARemoteEndpoint_t *remoteEndpoint);
103
104 /**
105  * @fn CAAdapterFreeRemoteEndpoint
106  * @brief Deallocate CARemoteEndpoint_t instance.
107  */
108 void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint);
109
110 /**
111  * @fn CAAdapterIsSameSubnet
112  * @brief Check if two ip address belong to same subnet
113  */
114 bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2,
115                            const char *netMask);
116 #ifdef __cplusplus
117 } /* extern "C" */
118 #endif
119 #endif  // _CA_ADAPTER_UTILS_H_