#include "camanagerleinterface.h"
#include "cabtpairinginterface.h"
#include "cautilinterface.h"
-
+#include "cainterfacecontroller.h"
#include "cacommon.h"
#include "logger.h"
#define TAG "OIC_CA_COMMON_UTILS"
+static CAAdapterStateChangedCB g_adapterStateCB = NULL;
+static CAConnectionStateChangedCB g_connStateCB = NULL;
+
+static void CAManagerAdapterMonitorHandler(CATransportAdapter_t adapter,
+ CANetworkStatus_t status)
+{
+ if (CA_INTERFACE_DOWN == status)
+ {
+ if (g_adapterStateCB)
+ {
+ g_adapterStateCB(adapter, false);
+ OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
+ }
+ }
+ else if (CA_INTERFACE_UP == status)
+ {
+ if (g_adapterStateCB)
+ {
+ g_adapterStateCB(adapter, true);
+ OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
+ }
+ }
+}
+
+static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected)
+{
+ if (!info || !info->addr)
+ {
+ OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
+ return;
+ }
+
+ if (isConnected)
+ {
+ if (g_connStateCB)
+ {
+ g_connStateCB(info->adapter, info->addr, isConnected);
+ OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer");
+ }
+ }
+ else
+ {
+ if (g_connStateCB)
+ {
+ g_connStateCB(info->adapter, info->addr, isConnected);
+ OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer");
+ }
+ }
+}
+
CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
CAConnectionStateChangedCB connStateCB)
{
OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
-#ifdef LE_ADAPTER
- CASetLENetworkMonitorCallbacks(adapterStateCB, connStateCB);
- return CA_STATUS_OK;
-#else
- (void)adapterStateCB;
- (void)connStateCB;
- return CA_NOT_SUPPORTED;
-#endif
+ g_adapterStateCB = adapterStateCB;
+ g_connStateCB = connStateCB;
+ CASetNetworkMonitorCallbacks(CAManagerAdapterMonitorHandler,
+ CAManagerConnectionMonitorHandler);
+ return CA_STATUS_OK;
}
CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
{
OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
-#ifdef LE_ADAPTER
+#if defined(__ANDROID__) && defined(LE_ADAPTER)
return CASetLEClientAutoConnectionDeviceInfo(address);
#else
(void)address;
{
OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
-#ifdef LE_ADAPTER
+#if defined(__ANDROID__) && defined(LE_ADAPTER)
return CAUnsetLEClientAutoConnectionDeviceInfo(address);
#else
(void)address;