Esempio n. 1
0
const c_char*
cmx_participantAutoDetach(
    const c_char* participant,
    c_bool enable)
{
    u_participant up;
    u_result result;
    cmx_entity ce;

    ce = cmx_entityClaim(participant);

    if (ce == NULL) {
        goto errorGetEntity;
    }
    up = u_participant(ce->uentity);
    if (enable == FALSE) {
        result = u_observableRemoveListener(u_observable(up), cmx_participantDetach);
        if (result != U_RESULT_OK) {
            goto errorRemoveListener;
        }
    } else {
        result = u_observableAction(u_observable(up), cmx_participantInitDetach, NULL);
        if (result != U_RESULT_OK) {
            goto errorEntityAction;
        }
        result = u_observableAddListener(u_observable(up),
                                         V_EVENT_SERVICESTATE_CHANGED,
                                         cmx_participantDetach,
                                         u_serviceManagerNew(up));
        if (result != U_RESULT_OK) {
            goto errorInsertListener;
        }
    }
    cmx_entityRelease(ce);

    return CMX_RESULT_OK;
    
errorInsertListener:
errorEntityAction:
errorRemoveListener:
errorGetEntity:
    return CMX_RESULT_FAILED;
}
Esempio n. 2
0
u_result
u_serviceInit(
    u_service service,
    u_serviceKind kind,
    u_domain domain)
{
    u_result r;
    watchSplicedAdmin admin;

    if ((service != NULL) && (domain != NULL)) {
        admin = watchSplicedAdmin(os_malloc((os_uint32)C_SIZEOF(watchSplicedAdmin)));
        service->stt = NULL;
        if (admin != NULL) {
            service->serviceKind = kind;
            r = u_participantInit(u_participant(service), domain);
            if (r == U_RESULT_OK) {
                admin->serviceManager = u_serviceManagerNew(u_participant(service));
                admin->callback = NULL;
                admin->usrData = NULL;
                service->privateData = (c_voidp)admin;
                u_entity(service)->flags |= U_ECREATE_INITIALISED;
            } else {
                OS_REPORT(OS_ERROR,"u_serviceInit",0,
                          "Initialization of the Participant failed.");
            }
        } else {
            service->privateData = NULL;
            OS_REPORT(OS_ERROR,"u_serviceInit",0,
                      "Failed to allocate resources.");
            r = U_RESULT_OUT_OF_MEMORY;
        }
    } else {
        OS_REPORT(OS_ERROR,"u_serviceInit",0,
                  "Illegal parameter.");
        r = U_RESULT_ILL_PARAM;
    }
    return r;
}
Esempio n. 3
0
static void
nw_serviceMain(
    const char *serviceName,
    const char *URI)
{
    u_serviceManager serviceManager;
    os_time sleepTime;
    os_result waitResult;
    nw_termination terminate;
    os_mutexAttr termMtxAttr;
    os_condAttr termCvAttr;
	c_bool fatal = FALSE;
    v_duration leasePeriod;
    terminate.terminate = FALSE;

    os_mutexAttrInit( & termMtxAttr );
    os_condAttrInit( & termCvAttr );
    termMtxAttr.scopeAttr = OS_SCOPE_PRIVATE;
    termCvAttr.scopeAttr = OS_SCOPE_PRIVATE;
    os_mutexInit( &terminate.mtx, &termMtxAttr );
    os_condInit( &terminate.cv, &terminate.mtx, &termCvAttr );

     /* Create networking service with kernel */
   service = u_serviceNew(URI, NW_ATTACH_TIMEOUT, serviceName, NULL,
                          U_SERVICE_NETWORKING, NULL);
    /* Initialize configuration */
   nw_configurationInitialize(service, serviceName, URI);

    /* Ask service manager for splicedaemon state */
    serviceManager = u_serviceManagerNew(u_participant(service));

    /* Create the controller which starts the updating */
    /* and calls the listener on a fatal error */
    controller = nw_controllerNew(service,controller_onfatal,&fatal);

    if (controller) {
		os_procAtExit(on_exit_handler);
        /* Start the actual engine */
        NW_REPORT_INFO(1, "Networking started");
        NW_TRACE(Mainloop, 1, "Networking started");

        nw_controllerStart(controller);
        /* Change state for spliced */
        u_serviceChangeState(service, STATE_INITIALISING);
        u_serviceChangeState(service, STATE_OPERATIONAL);
        /* Get sleeptime from configuration */
        nw_retrieveLeaseSettings(&leasePeriod, &sleepTime);
        /*sleepTime.tv_sec = 1; */

        /* Loop until termination is requested */
        u_serviceWatchSpliceDaemon(service, nw_splicedaemonListener,
                                   &terminate);
	os_mutexLock( &terminate.mtx );
        while ((!(int)terminate.terminate) && (!(int)fatal) && (!(int)f_exit)) {
            /* Assert my liveliness and the Splicedaemon's liveliness*/
            u_serviceRenewLease(service, leasePeriod);
            /* Check if anybody is still remotely interested */
            nw_controllerUpdateHeartbeats(controller);
            /* Wait before renewing again */
	        waitResult = os_condTimedWait( &terminate.cv, &terminate.mtx, &sleepTime );
	        if (waitResult == os_resultFail)
            {
                OS_REPORT(OS_CRITICAL, "nw_serviceMain", 0,
                          "os_condTimedWait failed - thread will terminate");
                fatal = TRUE;
            }
/* QAC EXPECT 2467; Control variable, terminate, not modified inside loop. That is correct, it is modified by another thread */
        }
	os_mutexUnlock( &terminate.mtx );
		/* keep process here waiting for the exit processing */
		while ((int)f_exit){os_nanoSleep(sleepTime);}

		if (!(int)fatal ) {
			leasePeriod.seconds = 20;
			leasePeriod.nanoseconds = 0;
			u_serviceRenewLease(service, leasePeriod);
	        u_serviceChangeState(service, STATE_TERMINATING);

	        nw_controllerStop(controller);
	        nw_controllerFree(controller);
			controller = NULL;
	        NW_REPORT_INFO(1, "Networking stopped");
	        NW_TRACE(Mainloop, 1, "Networking stopped");
		}
    }
	if (!(int)fatal ) {
	    nw_configurationFinalize();

	    /* Clean up */
	    u_serviceChangeState(service, STATE_TERMINATED);
		u_serviceManagerFree(serviceManager);

		u_serviceFree(service);
	}
}
Esempio n. 4
0
void
in_serviceMain(
    const os_char* serviceName,
    const os_char* uri)
{
    u_service service;
    in_config config;
    in_result result;
    u_serviceManager serviceManager;
    in_controller controller;
    v_duration leasePeriod;
    os_time sleepTime;
    os_boolean terminate = OS_FALSE;
    in_connectivityAdmin admin;

    assert(serviceName);
    assert(uri);

    /* Create networking service with kernel */
    service = u_serviceNew(
        uri,
        IN_ATTACH_TIMEOUT,
        serviceName,
        NULL,
        U_SERVICE_NETWORKING,
        NULL);
    assert(service);
    /* Initialize configuration */
    config = in_configGetInstance();
    result = in_configConvertDomTree(config, uri, service);
    if(result == IN_RESULT_OK)
    {
        /* Ask service manager for splicedaemon state */
        serviceManager = u_serviceManagerNew(u_participant(service));

        admin = in_connectivityAdminGetInstance();
        /* Create the controller which starts the updating */
        controller = in_controllerNew(service);
        if (controller)
        {
            /* Start the actual engine */
            IN_REPORT_INFO(1, "DDSI networking started");
            IN_TRACE(Mainloop, 1, "DDSI networking started");
            in_controllerStart(controller);
            /* Change state for spliced */
            u_serviceChangeState(service, STATE_INITIALISING);
            u_serviceChangeState(service, STATE_OPERATIONAL);
            /* Get sleeptime from configuration */
            in_retrieveLeaseSettings(&leasePeriod, &sleepTime);

            u_serviceRenewLease(service, leasePeriod);
            /* Loop until termination is requested */
            u_serviceWatchSpliceDaemon(
                service,
                in_splicedaemonListener,
                &terminate);
            /* terminate flag is modified by the splice deamon listener thread*/
            while (!terminate)
            {
                /* Assert my liveliness and the Splicedaemon's liveliness */
                u_serviceRenewLease(service, leasePeriod);
                /* Wait before renewing again */
                os_nanoSleep(sleepTime);
            }
            leasePeriod.seconds = 20;
            u_serviceRenewLease(service, leasePeriod);
            u_serviceChangeState(service, STATE_TERMINATING);
            in_controllerStop(controller);
            in_controllerFree(controller);
            IN_REPORT_INFO(1, "DDSI networking stopped");
            IN_TRACE(Mainloop, 1, "DDSI networking stopped");
        }
        u_serviceChangeState(service, STATE_TERMINATED);
		u_serviceManagerFree(serviceManager);
		in_objectFree(in_object(admin));
    }
    /* Clean up */
    in_configFree(config);
    u_serviceFree(service);
}