1 /******************************************************************
3 * Copyright 2019 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 #include "caipnwmonitor.h"
22 #include "caipnwmonitor_common.h"
27 #define TAG "OIC_CA_IP_MONITOR_COMMON"
30 * @todo For Windows platform: Implement network interface monitoring.
31 * Not used in win32, but caipserver currently requires this function
32 * be defined. not critical.
34 int CAGetPollingInterval(int interval)
39 void CAIPPassNetworkChangesToAdapterInternal(CANetworkStatus_t status,
40 CAIPCBData_t *adapterCallbackList, CAIPAdapterPlatform_t platform)
42 CAIPCBData_t *cbitem = NULL;
43 LL_FOREACH(adapterCallbackList, cbitem)
45 if (cbitem && cbitem->adapter)
47 cbitem->callback(cbitem->adapter, status);
48 if (platform == CA_IP_NW_COMMON_LINUX)
50 CALogAdapterStateInfo(cbitem->adapter, status);
56 CAResult_t CAIPSetNetworkMonitorCallbackInternal(CAIPAdapterStateChangeCallback callback,
57 CATransportAdapter_t adapter, CAIPCBData_t *adapterCallbackList)
61 OIC_LOG(ERROR, TAG, "callback is null");
62 return CA_STATUS_INVALID_PARAM;
65 CAIPCBData_t *cbitem = NULL;
66 LL_FOREACH(adapterCallbackList, cbitem)
68 if (cbitem && adapter == cbitem->adapter && callback == cbitem->callback)
70 OIC_LOG(DEBUG, TAG, "this callback is already added");
75 cbitem = (CAIPCBData_t *)OICCalloc(1, sizeof(*cbitem));
78 OIC_LOG(ERROR, TAG, "Malloc failed");
79 return CA_STATUS_FAILED;
82 cbitem->adapter = adapter;
83 cbitem->callback = callback;
84 LL_APPEND(adapterCallbackList, cbitem);
89 CAResult_t CAIPUnSetNetworkMonitorCallbackInternal(CATransportAdapter_t adapter,
90 CAIPCBData_t *adapterCallbackList)
92 CAIPCBData_t *cbitem = NULL;
93 CAIPCBData_t *tmpCbitem = NULL;
94 LL_FOREACH_SAFE(adapterCallbackList, cbitem, tmpCbitem)
96 if (cbitem && adapter == cbitem->adapter)
98 OIC_LOG(DEBUG, TAG, "remove specific callback");
99 LL_DELETE(adapterCallbackList, cbitem);