Make OCProcessEvent method.
[platform/upstream/iotivity.git] / resource / csdk / routing / src / routingmanager.c
old mode 100644 (file)
new mode 100755 (executable)
index 9f87d2f..fb4afac
@@ -714,7 +714,21 @@ exit:
     return result;
 }
 
-void RMProcess()
+#ifdef WITH_PROCESS_EVENT
+static void compareAndApplyTimeout(uint32_t *nextEventTime,
+                                   uint64_t timeoutSec)
+{
+    uint32_t timeoutMs = timeoutSec * MS_PER_SEC;
+    if (timeoutMs < *nextEventTime)
+    {
+        *nextEventTime = timeoutMs;
+    }
+}
+
+void RMProcess(uint32_t *nextEventTime)
+#else   // WITH_PROCESS_EVENT
+void RMProcess(void)
+#endif  // !WITH_PROCESS_EVENT
 {
     if (!g_isRMInitialized)
     {
@@ -741,7 +755,17 @@ void RMProcess()
         result = RMSendNotificationToAll(payload);
         RMPFreePayload(payload);
         RM_VERIFY_SUCCESS(result, OC_STACK_OK);
+#ifdef WITH_PROCESS_EVENT
+        compareAndApplyTimeout(nextEventTime, GATEWAY_ALIVE_TIMEOUT);
+#endif // WITH_PROCESS_EVENT
+    }
+#ifdef WITH_PROCESS_EVENT
+    else
+    {
+        compareAndApplyTimeout(nextEventTime,
+            GATEWAY_ALIVE_TIMEOUT - (currentTime - g_aliveTime));
     }
+#endif // WITH_PROCESS_EVENT
 
     if (ROUTINGTABLE_VALIDATION_TIMEOUT <= currentTime - g_refreshTableTime)
     {
@@ -770,8 +794,18 @@ void RMProcess()
         g_refreshTableTime = currentTime;
         g_isValidated = false;
         u_linklist_free(&removedEntries);
+#ifdef WITH_PROCESS_EVENT
+        compareAndApplyTimeout(nextEventTime, ROUTINGTABLE_VALIDATION_TIMEOUT);
+#endif // WITH_PROCESS_EVENT
         goto exit;
     }
+#ifdef WITH_PROCESS_EVENT
+    else
+    {
+        compareAndApplyTimeout(nextEventTime,
+            ROUTINGTABLE_VALIDATION_TIMEOUT - (currentTime - g_refreshTableTime));
+    }
+#endif // WITH_PROCESS_EVENT
 
     if (!g_isValidated && ROUTINGTABLE_REFRESH_TIMEOUT <= (currentTime - g_refreshTableTime))
     {
@@ -799,7 +833,17 @@ void RMProcess()
         g_isValidated = true;
         RTMPrintTable(g_routingGatewayTable, g_routingEndpointTable);
         u_linklist_free(&invalidInterfaces);
+#ifdef WITH_PROCESS_EVENT
+        compareAndApplyTimeout(nextEventTime, ROUTINGTABLE_REFRESH_TIMEOUT);
+#endif // WITH_PROCESS_EVENT
+    }
+#ifdef WITH_PROCESS_EVENT
+    else
+    {
+        compareAndApplyTimeout(nextEventTime,
+            ROUTINGTABLE_REFRESH_TIMEOUT - (currentTime - g_refreshTableTime));
     }
+#endif // WITH_PROCESS_EVENT
 
 exit:
     return;