예제 #1
0
static int do_start(const std::vector<std::string>& args) {
    Service* svc = ServiceManager::GetInstance().FindServiceByName(args[1]);
    if (!svc) {
        ERROR("do_start: Service %s not found\n", args[1].c_str());
        return -1;
    }
    if (!svc->Start())
        return -1;
    return 0;
}
예제 #2
0
static int do_exec(const std::vector<std::string>& args) {
    Service* svc = ServiceManager::GetInstance().MakeExecOneshotService(args);
    if (!svc) {
        return -1;
    }
    if (!svc->Start()) {
        return -1;
    }
    waiting_for_exec = true;
    return 0;
}
예제 #3
0
void PipeServer::Start(TCHAR const * name) {
    InitializeSecurityAttribute(&securityAttributes);
    HRESULT result = S_OK;
    if(FAILED(result = HRESULT_FROM_WIN32(acceptor.Open(name, &securityAttributes)))) {
        if(onError) {
            onError(this, result, userData);
        }
    }
    else {
        this->AcceptNext();
    }
    if(started) service.Start();
    else service.Run();
}    
bool ServiceManager::StartService(LPCSTR p_serviceID)
{
	ATOM serviceID = FindAtomA(p_serviceID);
	Service *service = GetService(p_serviceID);
	if (service)
	{
		TRACE("Starting %s", p_serviceID);
		return service->Start(serviceID);
	}
	else
	{
		return false;
	}
}
예제 #5
0
void handle_control_message(const std::string& msg, const std::string& name) {
    Service* svc = ServiceManager::GetInstance().FindServiceByName(name);
    if (svc == nullptr) {
        ERROR("no such service '%s'\n", name.c_str());
        return;
    }

    if (msg == "start") {
        svc->Start();
    } else if (msg == "stop") {
        svc->Stop();
    } else if (msg == "restart") {
        svc->Restart();
    } else {
        ERROR("unknown control msg '%s'\n", msg.c_str());
    }
}
예제 #6
0
static void msg_start(const std::string& name)
{
    Service* svc = nullptr;
    std::vector<std::string> vargs;

    size_t colon_pos = name.find(':');
    if (colon_pos == std::string::npos) {
        svc = ServiceManager::GetInstance().FindServiceByName(name);
    } else {
        std::string service_name(name.substr(0, colon_pos));
        std::string args(name.substr(colon_pos + 1));
        vargs = android::base::Split(args, " ");

        svc = ServiceManager::GetInstance().FindServiceByName(service_name);
    }

    if (svc) {
        svc->Start(vargs);
    } else {
        ERROR("no such service '%s'\n", name.c_str());
    }
}
DWORD WINAPI ServiceManager::ServiceThread(LPVOID lpData)
{
	Service *service = reinterpret_cast<Service *>(lpData);
	return service->Start(service->m_serviceID);
}
예제 #8
0
int main(int argc, char* argv[])
{
	int Argument;
	char Message[512];
	SimpleString ServiceName;
	int ConnectionString = -1;
	int ConnectionObjects = -1;

	if ( argc < 2 )
	{
		Usage( "Two few parameters" );
	}

	if ( argv[1][0] == '-' )
	{
		Usage( "The first parameter *must* be the service name" );
	}
	ServiceName = argv[1];

	// Check argument before launching any registering process
	for( Argument = 2; Argument < argc; Argument++ )
	{
		if ( strcmp( "-o", argv[Argument]) == 0 )
		{
			if ( Argument+1 >= argc || argv[Argument+1][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing output name at parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}
			if ( Argument+2 >= argc || argv[Argument+2][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing description for output '%s' at parameter %d\n", argv[Argument+1], Argument+2 );
				Usage( (const char *)Message );
			}

			Argument += 2;
			continue;
		}

		if ( strcmp( "-i", argv[Argument]) == 0 )
		{
			if ( Argument+1 >= argc || argv[Argument+1][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing input name at parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}
			if ( Argument+2 >= argc || argv[Argument+2][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing description for input '%s' at parameter %d\n", argv[Argument+1], Argument+2 );
				Usage( (const char *)Message );
			}
			Argument += 2;
			continue;
		}

		if ( strcmp( "-io", argv[Argument]) == 0 )
		{
			if ( Argument+1 >= argc || argv[Argument+1][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing inoutput name at parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}
			if ( Argument+2 >= argc || argv[Argument+2][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing description for inoutput '%s' at parameter %d\n", argv[Argument+1], Argument+2 );
				Usage( (const char *)Message );
			}
			Argument += 2;
			continue;
		}

		if ( strcmp( "-v", argv[Argument]) == 0 )
		{
			if ( Argument+1 >= argc || argv[Argument+1][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing variable name at parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}
			if ( Argument+2 >= argc || argv[Argument+2][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing description for variable '%s' at parameter %d\n", argv[Argument+1], Argument+2 );
				Usage( (const char *)Message );
			}
			if ( Argument+3 >= argc || argv[Argument+3][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing value for variable '%s' at parameter %d\n", argv[Argument+1], Argument+3 );
				Usage( (const char *)Message );
			}
			Argument += 3;
			continue;
		}

		if ( strcmp( "-ct", argv[Argument]) == 0 )
		{
			if ( Argument+1 >= argc || argv[Argument+1][0] == '-')
			{
				// We consider it as the name
				sprintf( Message, "Missing connection strint after parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}

			ConnectionString = Argument+1;

			ConnectionObjects = ParseConnectionString( argv[ConnectionString], false );
			if ( ConnectionObjects <= 0 )
			{
				sprintf( Message, "Bad connection string in parameter %d\n", Argument+1 );
				Usage( (const char *)Message );
			}

			Argument += 1;
			continue;
		}

		if ( strcmp( "-d", argv[Argument]) == 0 )
		{
			if ( Debug )
			{
				fprintf( stderr, "Warning: debug mode already set\n" );
			}
			Debug = true;
			continue;
		}

		sprintf( Message, "invalid option in parameter %d ('%s')", Argument+1, argv[Argument] );
		Usage( (const char *)Message );
	}

#ifdef _DEBUG
		// MsgSocket::Debug = MsgSocket::DBG_LINKSYNC;
#endif

	// Ok, it seems that parameters looks ok...
	// start registering service
	if ( Debug ) { printf("Launching service '%s' ", ServiceName.GetStr() ); }

	Service * pServ = ServiceFactory.Create( ServiceName );
	if ( Debug ) { printf("with ServiceId %s\n", pServ->GetPeerIdAsString().GetStr() ); }

	// Check argument before launching any registering process
	for( Argument = 2; Argument < argc; Argument++ )
	{
		if ( strcmp( "-o", argv[Argument]) == 0 )
		{
			pServ->AddConnector( argv[Argument+1], argv[Argument+2], AnOutput );

			Argument += 2;
			continue;
		}

		if ( strcmp( "-i", argv[Argument]) == 0 )
		{
			pServ->AddConnector( argv[Argument+1], argv[Argument+2], AnInput );

			Argument += 2;
			continue;
		}

		if ( strcmp( "-io", argv[Argument]) == 0 )
		{
			pServ->AddConnector( argv[Argument+1], argv[Argument+2], AnInOutput );

			Argument += 2;
			continue;
		}

		if ( strcmp( "-v", argv[Argument]) == 0 )
		{
			if ( Debug ) { printf( "Adding variable '%s' ('%s') with value '%s'...", argv[Argument+1], argv[Argument+2], argv[Argument+3] ); }

			if ( pServ->AddVariable( argv[Argument+1], SimpleString::EmptyString, argv[Argument+2], ReadWriteAccess ) == true )
			{
				pServ->SetVariableValue( argv[Argument+1], argv[Argument+3] );
				if ( Debug ) { printf( "done.\n" ); }
			}
			else
			{
				if ( Debug ) { printf( "failed.\n" ); }
			}

			Argument += 3;
			continue;
		}

		if ( strcmp( "-ct", argv[Argument]) == 0 )
		{
			// Already processed
			Argument += 1;
			 continue;
		}

		if ( strcmp( "-d", argv[Argument]) == 0 )
		{
			// Debug option already processed int the validity checking mode
			 continue;
		}

		sprintf( Message, "invalid option in parameter %d ('%s')", Argument+1, argv[Argument] );
		Usage( (const char *)Message );
	}

	pServ->Start();

	printf( "Waiting...\n" );
	// Lock Mylself
	Event ForEver;
	ForEver.Wait();

	return 0;
}