[IOT-1346] Enable network status monitoring for tcp network
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caipnwmonitor.h
1 /******************************************************************
2  *
3  * Copyright 2016 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 caipnwmonitor.h
23  * This file provides APIs IP network monitor modules.
24  */
25
26 #ifndef CA_IP_NW_INTERFACE_H_
27 #define CA_IP_NW_INTERFACE_H_
28
29 #include "cacommon.h"
30 #include "cathreadpool.h"
31 #include "uarraylist.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 #define INTERFACE_NAME_MAX 16
39
40 /**
41  * Callback to be notified when IP adapter network state changes.
42  *
43  * @param[in]  adapter      Transport adapter.
44  * @param[in]  status       Connection status either ::CA_INTERFACE_UP or ::CA_INTERFACE_DOWN.
45  * @see CAIPSetConnectionStateChangeCallback() for registration.
46  */
47 typedef void (*CAIPAdapterStateChangeCallback)(CATransportAdapter_t adapter,
48                                                CANetworkStatus_t status);
49
50 typedef struct
51 {
52     char name[INTERFACE_NAME_MAX];
53     uint32_t index;
54     uint32_t flags;
55     uint16_t family;
56     char addr[MAX_ADDR_STR_SIZE_CA];
57 } CAInterface_t;
58
59 typedef struct CAIPCBData_t
60 {
61     struct CAIPCBData_t *next;
62     CATransportAdapter_t adapter;
63     CAIPAdapterStateChangeCallback callback;
64 } CAIPCBData_t;
65
66 /**
67  * Set callback for receiving local IP/TCP adapter connection status.
68  *
69  * @param[in]  callback     Callback to be notified when IP/TCP adapter connection state changes.
70  * @param[in]  adapter      Transport adapter.
71  * @return ::CA_STATUS_OK or Appropriate error code.
72  */
73 CAResult_t CAIPSetNetworkMonitorCallback(CAIPAdapterStateChangeCallback callback,
74                                          CATransportAdapter_t adapter);
75
76 /**
77  * Unset callback for receiving local IP/TCP adapter connection status.
78  *
79  * @param[in]  adapter      Transport adapter.
80  * @return ::CA_STATUS_OK or Appropriate error code.
81  */
82 CAResult_t CAIPUnSetNetworkMonitorCallback(CATransportAdapter_t adapter);
83
84 /**
85  * Get a list of CAInterface_t items.
86  *
87  * @param[in]  desiredIndex      Network interface index.
88  * @return  List of CAInterface_t items.
89  */
90 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
91
92 /**
93  * Find a new network interface.
94  *
95  * @return  Description of interface (or NULL if no change)
96  */
97 CAInterface_t *CAFindInterfaceChange();
98
99 /**
100  * Start network monitor.
101  *
102  * @param[in]  callback     Callback to be notified when IP/TCP adapter connection state changes.
103  * @param[in]  adapter      Transport adapter.
104  * @return ::CA_STATUS_OK or Appropriate error code.
105  */
106 CAResult_t CAIPStartNetworkMonitor(CAIPAdapterStateChangeCallback callback,
107                                    CATransportAdapter_t adapter);
108
109 /**
110  * Stops network monitor.
111  *
112  * @param[in]  adapter      Transport adapter.
113  * @return ::CA_STATUS_OK or Appropriate error code.
114  */
115 CAResult_t CAIPStopNetworkMonitor(CATransportAdapter_t adapter);
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #endif /* CA_IP_NW_INTERFACE_H_ */