Пример #1
0
CAResult_t CAEthernetGetInterfaceInfo(char **interfaceName, char **ipAddress)
{
    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "IN");

    VERIFY_NON_NULL(interfaceName, ETHERNET_MONITOR_TAG, "interface name");
    VERIFY_NON_NULL(ipAddress, ETHERNET_MONITOR_TAG, "ip address");

    // Get the interface and ipaddress information from cache
    u_mutex_lock(g_ethernetNetInfoMutex);
    if (g_ethernetInterfaceName == NULL || g_ethernetIPAddress == NULL)
    {
        OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "Network not enabled");

        u_mutex_unlock(g_ethernetNetInfoMutex);
        return CA_ADAPTER_NOT_ENABLED;
    }

    *interfaceName = (g_ethernetInterfaceName) ? strndup(g_ethernetInterfaceName,
                     strlen(g_ethernetInterfaceName)) : NULL;
    *ipAddress = (g_ethernetIPAddress) ? OICStrdup((const char *)g_ethernetIPAddress)
                 : NULL;

    u_mutex_unlock(g_ethernetNetInfoMutex);

    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #2
0
/**
 * Return the dynamic stub with the given name.  If no such stub exists and
 * generate is true, a new stub is generated.
 */
struct mapi_stub *
stub_find_dynamic(const char *name, int generate)
{
   u_mutex_declare_static(dynamic_mutex);
   struct mapi_stub *stub = NULL;
   int count, i;
   
   u_mutex_lock(dynamic_mutex);

   if (generate)
      assert(!stub_find_public(name));

   count = num_dynamic_stubs;
   for (i = 0; i < count; i++) {
      if (strcmp(name, (const char *) dynamic_stubs[i].name) == 0) {
         stub = &dynamic_stubs[i];
         break;
      }
   }

   /* generate a dynamic stub */
   if (generate && !stub)
         stub = stub_add_dynamic(name);

   u_mutex_unlock(dynamic_mutex);

   return stub;
}
Пример #3
0
void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket)
{
    OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket");

    if(!g_deviceObjectList)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
        return;
    }

    u_mutex_lock(g_mutexSocketListManager);

    jint index;
    for (index = 0; index < u_arraylist_length(g_deviceObjectList); index++)
    {
        jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
        if(!jarrayObj)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
            continue;
        }

        jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
        if(!jni_setAddress)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
            continue;
        }
        const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);

        jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
        if(!jni_remoteAddress)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null");
            continue;
        }
        const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);

        if(!strcmp(setAddress, remoteAddress))
        {
            OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress);
            (*env)->DeleteGlobalRef(env, jarrayObj);

            CAEDRReorderingDeviceSocketList(index);
            break;
        }
    }
    u_mutex_unlock(g_mutexSocketListManager);

    OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object");
    return;
}
Пример #4
0
CAResult_t CAEthernetGetInterfaceSubnetMask(char **subnetMask)
{
    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "IN");

    VERIFY_NON_NULL(subnetMask, ETHERNET_MONITOR_TAG, "subnet mask");

    u_mutex_lock(g_ethernetNetInfoMutex);
    if (NULL == g_ethernetSubnetMask)
    {
        OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "There is no subnet mask information!");

        u_mutex_unlock(g_ethernetNetInfoMutex);
        return CA_STATUS_FAILED;
    }

    *subnetMask = (g_ethernetSubnetMask) ?
                  strndup(g_ethernetSubnetMask, strlen(g_ethernetSubnetMask))
                  : NULL;
    u_mutex_unlock(g_ethernetNetInfoMutex);

    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #5
0
void CANetworkMonitorThread(void *threadData)
{
    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "IN");

    while (!g_stopNetworkMonitor)
    {
        // Get network information
        char *interfaceName = NULL;
        char *ipAddress = NULL;
        char *subnetMask = NULL;
        CAEthernetGetInterfaceInformation(ETHERNET_INF_PREFIX,&interfaceName, &ipAddress, &subnetMask);

        // check current network status
        CANetworkStatus_t currNetworkStatus;
        currNetworkStatus = (ipAddress) ? CA_INTERFACE_UP : CA_INTERFACE_DOWN;

        // if network status is changed
        if (currNetworkStatus != nwConnectivityStatus)
        {
            // set current network information
            u_mutex_lock(g_ethernetNetInfoMutex);

            nwConnectivityStatus = currNetworkStatus;

            OICFree(g_ethernetInterfaceName);
            OICFree(g_ethernetIPAddress);
            OICFree(g_ethernetSubnetMask);
            g_ethernetInterfaceName =
                (interfaceName) ? strndup(interfaceName, strlen(interfaceName)) : NULL;
            g_ethernetIPAddress = (ipAddress) ? strndup(ipAddress, strlen(ipAddress)) : NULL;
            g_ethernetSubnetMask = (subnetMask) ? strndup(subnetMask, strlen(subnetMask)) : NULL;

            u_mutex_unlock(g_ethernetNetInfoMutex);

            if (g_networkChangeCb)
            {
                g_networkChangeCb(g_ethernetIPAddress, nwConnectivityStatus);
            }
        }
        OICFree(interfaceName);
        OICFree(ipAddress);
        OICFree(subnetMask);
    }

    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT");
}
Пример #6
0
CAResult_t CAEthernetInitializeNetworkMonitor(const u_thread_pool_t threadPool)
{
    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "IN");

    g_threadPool = threadPool;

    if (!g_ethernetNetInfoMutex)
    {
        g_ethernetNetInfoMutex = u_mutex_new();
    }

    u_mutex_lock(g_ethernetNetInfoMutex);
    CAEthernetGetInterfaceInformation(ETHERNET_INF_PREFIX,&g_ethernetInterfaceName, &g_ethernetIPAddress,
                                      &g_ethernetSubnetMask);
    u_mutex_unlock(g_ethernetNetInfoMutex);

    nwConnectivityStatus = (g_ethernetIPAddress) ? CA_INTERFACE_UP : CA_INTERFACE_DOWN;

    OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #7
0
/**
 * We should call this periodically from a function such as glXMakeCurrent
 * in order to test if multiple threads are being used.
 */
void
u_current_init(void)
{
   static unsigned long knownID;
   static int firstCall = 1;

   if (ThreadSafe)
      return;

   u_mutex_lock(ThreadCheckMutex);
   if (firstCall) {
      u_current_init_tsd();

      knownID = u_thread_self();
      firstCall = 0;
   }
   else if (knownID != u_thread_self()) {
      ThreadSafe = 1;
      u_current_set(NULL);
      u_current_set_user(NULL);
   }
   u_mutex_unlock(ThreadCheckMutex);
}
Пример #8
0
void *
u_execmem_alloc(unsigned int size)
{
   void *addr = NULL;

   u_mutex_lock(exec_mutex);

   if (!init_map())
      goto bail;

   /* free space check, assumes no integer overflow */
   if (head + size > EXEC_MAP_SIZE)
      goto bail;

   /* allocation, assumes proper addr and size alignement */
   addr = exec_mem + head;
   head += size;

bail:
   u_mutex_unlock(exec_mutex);

   return addr;
}
Пример #9
0
void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket)
{
    OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeAddDeviceobjToList");

    if(!deviceSocket)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] Device is null");
        return;
    }

    if(!g_deviceObjectList)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null");
        return;
    }

    jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket);
    if(!jni_remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] jni_remoteAddress is null");
        return;
    }

    u_mutex_lock(g_mutexSocketListManager);

    const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);

    if(!CAEDRNativeIsDeviceSocketInList(env, remoteAddress))
    {
        jobject gDeviceSocker = (*env)->NewGlobalRef(env, deviceSocket);
        u_arraylist_add(g_deviceObjectList, gDeviceSocker);
        OIC_LOG(DEBUG, TAG, "Set Socket Object to Array");
    }

    u_mutex_unlock(g_mutexSocketListManager);
}