Beispiel #1
0
int PluginLoop(void*){

		WatchHandle watch = CreateWatch("*", "*", "*");

		while(running){

				Notification notif;
				if(GetNotification(&notif, 0)){
						PLUGIN_INFO("notification received: %d.\n", notif.type);
						int res = 0;

						switch (notif.type) {
								case kShutdown:
										running = false;
										break;
								case kWatch:
										PluginInfo info;
										res = GetPluginInfo(notif.content.watch.plugin, &info);
										PLUGIN_INFO("plugin %s(%s) available\n", info.name, info.version);
										if(watch == notif.content.watch.handle && notif.content.watch.plugin_state == kPluginAvailable) {
												Connect(notif.content.watch.plugin);
										}
										break;
								default:
										break;
						}
						// process notification
				}
		}
		return 0;
}
Notification_Ptr NotificationQueue::WaitForNotification( vuint32 in_TimeOut_ms )
{
	Notification_Ptr pRes = GetNotification();
	
	// WaitForNotification() returns NULL in 2 cases:
	// - The queue was "closed" (the way to finish the thread which is running this function);
	// - timeout reached.
	//
	vuint32 timeOut = (in_TimeOut_ms) ? in_TimeOut_ms : ULONG_MAX;
	while( mIsOpen.load() && pRes == nullptr )
	{
		StLockGuard_T<NQ_MUTEX> guard( mNQConditionVarMutex );
		
		if( mNotificationAvailable.wait_for( guard, timeOut ) == false )
			break;
			
		pRes = GetNotification();
	}

	return pRes;
}
Beispiel #3
0
int PluginLoop(void *) {
  PLUGIN_INFO("thread started");
  g_plugin->OnThreadEntry();

  unsigned int last_time = Base::Time::GetTimeMs();
  while(g_running) {
    Notification notif;
    if(GetNotification(&notif, g_plugin->IdleDt())) {
      // PLUGIN_INFO("notification received: %d.", notif.type);
      g_plugin->OnNotification(notif);
      switch(notif.type) {
      case kShutdown:
        g_plugin->OnShutdown(notif.content.shutdown);
        g_running = false;
        break;
      case kWatch: {
        PluginInfo info;
        if(0 == GetPluginInfo(notif.content.watch.plugin, &info)) {
          PLUGIN_INFO("watch plugin match %s(%s) for %p", info.name,
                      info.version, notif.content.watch.handle);
        } else {
          PLUGIN_WARN("unknown plugin match for %p",
                      notif.content.connection.endpoint);
        }
        g_plugin->OnWatchMatch(notif.content.watch);
        break;
      }
      case kConfigChanged:
        g_plugin->OnConfigChange(notif.content.config);
        break;
      case kEstablished: {
        PluginInfo info;
        if(0 == GetPluginInfo(notif.content.connection.endpoint, &info)) {
          PLUGIN_INFO("connected to %s(%s)", info.name, info.version);
        } else {
          PLUGIN_WARN("connected to unknown plugin %p",
                      notif.content.connection.endpoint);
        }
        g_plugin->OnConnected(notif.content.connection);
        break;
      }
      case kConnected: {
        PluginInfo info;
        if(0 == GetPluginInfo(notif.content.connection.endpoint, &info)) {
          PLUGIN_INFO("plugin connected %s(%s)", info.name, info.version);
        } else {
          PLUGIN_WARN("unknown plugin connected %p",
                      notif.content.connection.endpoint);
        }
        g_plugin->OnPluginConnected(notif.content.connection);
        break;
      }
      case kDisconnected:
        PluginInfo info;
        if(0 == GetPluginInfo(notif.content.connection.endpoint, &info)) {
          PLUGIN_INFO("plugin disconnected %s(%s)", info.name, info.version);
        } else {
          PLUGIN_WARN("unknown plugin disconnected %p",
                      notif.content.connection.endpoint);
        }
        g_plugin->OnDisconnected(notif.content.connection);
        break;
      case kRecvReady:
        g_plugin->OnRecvReady(notif.content.connection);
      default:
        break;
      }
    }

    unsigned int now = Base::Time::GetTimeMs();
    unsigned int dt = now - last_time;
    g_plugin->OnUpdate(dt);
    last_time = now;
  }

  g_plugin->OnThreadExit();
  PLUGIN_INFO("thread exiting");
  return 0;
}