Пример #1
0
void CheckHandlerStatus(struct kepalive_ctx* ctx)
{
	Handler_Loader_Interface *pInterfaceTmp = NULL;
	if(!ctx)
		return;
	pInterfaceTmp = ctx->pHandlerList->items;
	while(pInterfaceTmp)
	{
		HANDLER_THREAD_STATUS pOutStatus;
		bool bRestart = false;
		if(pInterfaceTmp->Workable == false)
		{
			pInterfaceTmp = pInterfaceTmp->next;
			continue;
		}
		if(pInterfaceTmp->type != user_handler)
		{
			pInterfaceTmp = pInterfaceTmp->next;
			continue;
		}

		if(!ctx->isThreadRunning)
			break;

		if(pInterfaceTmp->Handler_Get_Status_API)
		{
			handler_result result = pInterfaceTmp->Handler_Get_Status_API(&pOutStatus);
			if(result == handler_success)
			{
				handler_countdown_st *phandlercd = FindHandlerCD(pInterfaceTmp->Name);
				if(pOutStatus == handler_status_busy)
				{
					if(!phandlercd)
					{
						phandlercd = AddhHandlerCD(pInterfaceTmp->Name, 3);
					}
					phandlercd->count++;
					SAManagerLog(g_keepalivelogger, Warning, "Handler %s is busy count %d!", pInterfaceTmp->Name, phandlercd->count);
					if(phandlercd->count >= phandlercd->limit)
					{
						bRestart = true;
						RemoveHandlerCD(pInterfaceTmp->Name);
					}
				}
				else if(phandlercd)
				{
					RemoveHandlerCD(pInterfaceTmp->Name);
				}
			}
		}
		
		if(!ctx->isThreadRunning)
			break;

		if(bRestart)
		{
			if(pInterfaceTmp->Handler_Stop_API)
			{
				SAManagerLog(g_keepalivelogger, Warning, "Stop Handler %s!", pInterfaceTmp->Name);
				pInterfaceTmp->Handler_Stop_API();
			}

			if(!ctx->isThreadRunning)
				break;

			if(pInterfaceTmp->Handler_Start_API)
			{
				SAManagerLog(g_keepalivelogger, Warning, "Restart Handler %s!", pInterfaceTmp->Name);
				pInterfaceTmp->Handler_Start_API();
			}
		}
		pInterfaceTmp = pInterfaceTmp->next;
	}
}
Пример #2
0
void hlloader_handler_recv(SALoader_Interface* pSALoader, Handler_List_t *pHandlerList, char* topic, susiaccess_packet_body_t *pkt, void *pRev1, void* pRev2)
{
	Handler_Loader_Interface* handler = NULL;
	char* pReqInfoPayload = NULL;
	
	if(!pSALoader)
		return;

	pReqInfoPayload = pkg_parser_packet_print(pkt);

	if(pSALoader->Loader_FindHandler_API)
	{
		/*Support V3.1 Version */
		handler = pSALoader->Loader_FindHandler_API(pHandlerList, pkt->handlerName);
	}
	if(handler != NULL)
	{
		if( handler->Handler_Recv_API )
			handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
	}

	/*Support V3.0 or Older Version */
	else{
		int reqID = pkt->requestID;
		if(pSALoader)
		{
			/*Support V3.0 Version */
			handler = pSALoader->Loader_FindHandlerByReqID_API(pHandlerList, reqID);
		}
		if(handler != NULL)
		{
			if( handler->Handler_Recv_API )
				handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
		}
		/*Support Older Version */
		else if(reqID == cagent_request_device_monitoring)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "device_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "device_monitoring" );
			}
		}
		else if(reqID == cagent_request_power_onoff)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "power_onoff");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "power_onoff" );
			}
		}
		else if(reqID == cagent_request_remote_kvm)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "remote_kvm");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "remote_kvm" );
			}
		}
		else if(reqID == cagent_request_protection)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "protection");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "protection" );
			}
		}
		else if(reqID == cagent_request_recovery)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "recovery");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "recovery" );
			}
		}
		else if(reqID == cagent_request_software_monitoring)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "software_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "software_monitoring" );
			}
		}
		else if(reqID == cagent_request_global)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "general");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "global" );
			}
		}
		else if(reqID == cagent_request_terminal)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "terminal");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "terminal" );
			}
		}
		else if(reqID == cagent_request_screenshot)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "screenshot");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "screenshot" );
			}
		}
	}
	free(pReqInfoPayload);
}
Пример #3
0
void SAManager_RecvInternalCommandReq(char* topic, susiaccess_packet_body_t *pkt, void *pRev1, void* pRev2)
{
	Handler_Loader_Interface* handler = NULL;
	PJSON ReqInfoJSON = NULL;
	char* pReqInfoPayload = NULL;
	ReqInfoJSON = SAParser_CreateAgentPacketToJSON(pkt);
	pReqInfoPayload = SAParser_PrintUnformatted(ReqInfoJSON);
	SAParser_Free(ReqInfoJSON);

	if(g_SALoader)
	{
		/*Support V3.1 Version */
		handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, pkt->handlerName);
	}
	if(handler != NULL)
	{
		//SAManagerLog(g_samanagerlogger, Normal, "Handler find by name: %s", pkt->handlerName );
		if( handler->Handler_Recv_API )
			handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
	}
	/*Support V3.0 or Older Version */
	else{
		int reqID = pkt->requestID;
		if(g_SALoader)
		{
			/*Support V3.0 Version */
			handler = g_SALoader->Loader_FindHandlerByReqID_API(&g_handlerList, reqID);
		}
		if(handler != NULL)
		{
			//SAManagerLog(g_samanagerlogger, Normal, "Handler find by ID: %d", reqID );
			if( handler->Handler_Recv_API )
				handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
		}
		/*Support Older Version */
		else if(reqID == cagent_request_device_monitoring)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "device_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "device_monitoring" );
			}
		}
		else if(reqID == cagent_request_power_onoff)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "power_onoff");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "power_onoff" );
			}
		}
		else if(reqID == cagent_request_remote_kvm)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "remote_kvm");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "remote_kvm" );
			}
		}
		else if(reqID == cagent_request_protection)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "protection");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "protection" );
			}
		}
		else if(reqID == cagent_request_recovery)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "recovery");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "recovery" );
			}
		}
		else if(reqID == cagent_request_software_monitoring)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "software_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "software_monitoring" );
			}
		}
		else if(reqID == cagent_request_global)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "general");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "global" );
			}
		}
		else if(reqID == cagent_request_terminal)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "terminal");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "terminal" );
			}
		}
		else if(reqID == cagent_request_screenshot)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "screenshot");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "screenshot" );
			}
		}
	}
	free(pReqInfoPayload);
}