コード例 #1
0
ファイル: smfd_amf.c プロジェクト: indonexia2004/opensaf-indo
/**************************************************************************
 Function: smfd_amf_init

 Purpose:  Function which initializes SMFD with AMF.  

 Input:    None 

 Returns:  SA_AIS_OK    - everything is OK
           SA_AIS_ERR_* - failure

**************************************************************************/
SaAisErrorT smfd_amf_init(smfd_cb_t * cb)
{
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT result;

	TRACE_ENTER();

	/* Initialize AMF callbacks */
	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));
	amfCallbacks.saAmfHealthcheckCallback = amf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = amf_csi_set_callback;
	amfCallbacks.saAmfComponentTerminateCallback =
	    amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = amf_csi_rmv_callback;

	amf_version.releaseCode = 'B';
	amf_version.majorVersion = 0x01;
	amf_version.minorVersion = 0x01;

	/* Initialize the AMF library */
	result = saAmfInitialize(&cb->amf_hdl, &amfCallbacks, &amf_version);
	if (result != SA_AIS_OK) {
		LOG_ER("saAmfInitialize() FAILED: %u", result);
		goto done;
	}

	/* Obtain the AMF selection object to wait for AMF events */
	result = saAmfSelectionObjectGet(cb->amf_hdl, &cb->amfSelectionObject);
	if (result != SA_AIS_OK) {
		LOG_ER("saAmfSelectionObjectGet() FAILED: %u", result);
		goto done;
	}

	/* Get the component name */
	result = saAmfComponentNameGet(cb->amf_hdl, &cb->comp_name);
	if (result != SA_AIS_OK) {
		LOG_ER("saAmfComponentNameGet() FAILED: %u", result);
		goto done;
	}

	/* Register component with AMF */
	result =
	    saAmfComponentRegister(cb->amf_hdl, &cb->comp_name,
				   (SaNameT *) NULL);
	if (result != SA_AIS_OK) {
		LOG_ER("saAmfComponentRegister() FAILED");
		goto done;
	}

	/* Start AMF healthchecks */
	if ((result = amf_healthcheck_start(cb)) != SA_AIS_OK) {
		LOG_ER("health check start FAILED");
		goto done;
	}

 done:
	TRACE_LEAVE();
	return result;
}
コード例 #2
0
ファイル: plms_amf.c プロジェクト: helioloureiro/opensaf-fork
/**************************************************************************
 Function: plms_amf_register

 Purpose:  Function which registers PLMS with AMF.  

 Input:    Pointer to the PLMS control block. 

 Returns:  NCSCC_RC_SUCCESSS/NCSCC_RC_FAILURE

 Notes:  Here we call plms_amf_init after reading the component name file and
         setting the environment varaiable in our own context.
         Proceed to register with AMF, since it has come up. 
**************************************************************************/
SaUint32T plms_amf_register()
{

	SaAisErrorT error;
	uint32_t rc = NCSCC_RC_SUCCESS;
	PLMS_CB * cb = plms_cb;

	m_NCS_LOCK(&cb->cb_lock, NCS_LOCK_WRITE);

	/* Initialize amf framework for hc interface */
	if ((rc = plms_amf_init()) != NCSCC_RC_SUCCESS) {
		LOG_ER("AMF init failed");
		m_NCS_UNLOCK(&cb->cb_lock, NCS_LOCK_WRITE);
		return NCSCC_RC_FAILURE;
	}

	LOG_IN("AMF init SUCCESS");
	/* register PLMS component with AvSv */
	error = saAmfComponentRegister(cb->amf_hdl, &cb->comp_name, (SaNameT *)NULL);
	if (error != SA_AIS_OK) {
		LOG_ER("AMF Component Register failed");
		m_NCS_UNLOCK(&cb->cb_lock, NCS_LOCK_WRITE);
		return NCSCC_RC_FAILURE;
	}
	LOG_IN("AMF Component Register SUCCESS");
	if (NCSCC_RC_SUCCESS != (rc = plms_healthcheck_start())) {
		LOG_ER("PLMS Health Check Start failed");
		m_NCS_UNLOCK(&cb->cb_lock, NCS_LOCK_WRITE);
		return NCSCC_RC_FAILURE;
	}
	LOG_IN("PLMS Health Check Started Successfully SUCCESS");
	m_NCS_UNLOCK(&cb->cb_lock, NCS_LOCK_WRITE);

	return NCSCC_RC_SUCCESS;
}
コード例 #3
0
static void clMsgRegisterWithCpm(void)
{
    SaAisErrorT rc = SA_AIS_OK;
    SaAmfCallbacksT    callbacks = {0};
    SaVersionT  version = {0};

    version.releaseCode = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;
                                                                                                                             
    callbacks.saAmfHealthcheckCallback = NULL;
    callbacks.saAmfComponentTerminateCallback = safTerminate;
    callbacks.saAmfCSISetCallback = NULL;
    callbacks.saAmfCSIRemoveCallback = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
    

    rc = saAmfInitialize(&amfHandle, &callbacks, &version);
    if( rc != SA_AIS_OK)
    {
         clLogError("MSG", "INI", "saAmfInitialize failed with  error code [0x%x].", rc);
         return ;
    }


    rc = saAmfComponentNameGet(amfHandle, &appName);

    rc = saAmfComponentRegister(amfHandle, &appName, NULL);
}
void initializeAmf(void)
{
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    /* Get the pid for the process and store it in global variable. */
    mypid = getpid();

    /* SAFplus is fully API compatible with SA-Forum (SAF) definitions.

       This optional call customizes OpenClovis SAFplus Platform extensions
       to the basic SAF services (to use, you would define the parameters as globals).  
       
       If this call is removed, standard SAF services will work just fine. */

    /* clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs); */

    
    /*
     * Initialize and register with SAFplus AMF. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */
    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = safTerminate;
    callbacks.saAmfCSISetCallback               = safAssignWork;
    callbacks.saAmfCSIRemoveCallback            = safRemoveWork;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /* Initialize AMF client library. */
    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        errorExit(rc);

    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        errorExit(rc);
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        errorExit(rc);

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);
}
コード例 #5
0
static void safTerminate(SaInvocationT invocation, const SaNameT *compName)
{
    SaAisErrorT rc = SA_AIS_OK;
    if(gClMsgInit)
    {
        ClBoolT lockStatus = CL_TRUE;
        ClTimerTimeOutT timeout = {.tsSec = 0, .tsMilliSec = 0};
        clOsalMutexLock(&gClMsgFinalizeLock);
        while(gClMsgSvcRefCnt > 0)
        {
            clOsalCondWait(&gClMsgFinalizeCond, &gClMsgFinalizeLock, timeout);
        }
        safMsgFinalize(&lockStatus);
        if(lockStatus)
        {
            clOsalMutexUnlock(&gClMsgFinalizeLock);
        }
    }
    rc = saAmfComponentUnregister(amfHandle, compName, NULL);
    clCpmClientFinalize(amfHandle);
    //clCpmResponse(cpmHandle, invocation, CL_OK);
    saAmfResponse(amfHandle, invocation, SA_AIS_OK);
    
    return;
}


static void clMsgRegisterWithCpm(void)
{
    SaAisErrorT rc = SA_AIS_OK;
    SaAmfCallbacksT    callbacks = {0};
    SaVersionT  version = {0};

    version.releaseCode = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;
                                                                                                                             
    callbacks.saAmfHealthcheckCallback = NULL;
    callbacks.saAmfComponentTerminateCallback = safTerminate;
    callbacks.saAmfCSISetCallback = NULL;
    callbacks.saAmfCSIRemoveCallback = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
    

    rc = saAmfInitialize(&amfHandle, &callbacks, &version);
    if( rc != SA_AIS_OK)
    {
         clLogError("MSG", "INI", "saAmfInitialize failed with  error code [0x%x].", rc);
         return ;
    }


    rc = saAmfComponentNameGet(amfHandle, &appName);

    rc = saAmfComponentRegister(amfHandle, &appName, NULL);
}
コード例 #6
0
ファイル: rde_amf.c プロジェクト: kenzaburo/OpenSaf-FrameWork
uns32 rde_amf_init(RDE_AMF_CB *rde_amf_cb)
{
	uns32 rc = NCSCC_RC_SUCCESS;
	SaAisErrorT amf_error = SA_AIS_OK;
	SaNameT sname;
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;

	TRACE_ENTER();

	if (amf_comp_name_get_set_from_file("RDE_COMP_NAME_FILE", &sname) != NCSCC_RC_SUCCESS)
		return NCSCC_RC_FAILURE;

	amfCallbacks.saAmfHealthcheckCallback = rde_saf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = rde_saf_CSI_set_callback;
	amfCallbacks.saAmfCSIRemoveCallback = rde_saf_CSI_rem_callback;
	amfCallbacks.saAmfComponentTerminateCallback = rde_saf_comp_terminate_callback;

	m_RDE_GET_AMF_VER(amf_version);

	amf_error = saAmfInitialize(&rde_amf_cb->amf_hdl, &amfCallbacks, &amf_version);
	if (amf_error != SA_AIS_OK) {
		LOG_ER("saAmfInitialize FAILED %u", amf_error);
		return NCSCC_RC_FAILURE;
	}

	memset(&sname, 0, sizeof(sname));
	amf_error = saAmfComponentNameGet(rde_amf_cb->amf_hdl, &sname);
	if (amf_error != SA_AIS_OK) {
		LOG_ER("saAmfComponentNameGet FAILED %u", amf_error);
		return NCSCC_RC_FAILURE;
	}

	strcpy((char*)rde_amf_cb->comp_name, (char*)sname.value);

	amf_error = saAmfSelectionObjectGet(rde_amf_cb->amf_hdl, &rde_amf_cb->amf_fd);
	if (amf_error != SA_AIS_OK) {
		LOG_ER("saAmfSelectionObjectGet FAILED %u", amf_error);
		return NCSCC_RC_FAILURE;
	}

	amf_error = saAmfComponentRegister(rde_amf_cb->amf_hdl, &sname, (SaNameT *)NULL);
	if (amf_error != SA_AIS_OK) {
		LOG_ER("saAmfComponentRegister FAILED %u", amf_error);
		return NCSCC_RC_FAILURE;
	}

	rc = rde_amf_healthcheck_start(rde_amf_cb);
	if (rc != NCSCC_RC_SUCCESS)
		return NCSCC_RC_FAILURE;

	TRACE_LEAVE2("AMF Initialization SUCCESS......");
	return(rc);
}
int main (void) {
	SaAmfHandleT handle;
	int result;
	SaNameT compName;
	pthread_t dispatch_thread;
	pthread_attr_t dispatch_thread_attribute;

	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	if (result != SA_OK) {
		printf ("initialize result is %d\n", result);
		exit (1);
	}

	setSanameT (&compName, "comp_b_in_su_y");

	result = saAmfComponentRegister (&handle, &compName, NULL);
	printf ("register result is %d (should be 1)\n", result);

	pthread_attr_init (&dispatch_thread_attribute);
	pthread_attr_setschedpolicy (&dispatch_thread_attribute, SCHED_FIFO);
//	pthread_attr_setschedparam (&dispatch_thread_attribute, 99);
	pthread_create (&dispatch_thread, NULL, th_dispatch, &handle);

	sleep (5);

printf ("Finalizing handle\n");

	saAmfComponentUnregister (&handle, &compName, NULL);

	saAmfFinalize (&handle);

printf ("Handle Finalized\n");
	sleep (1); /* this sleep isn't really necessary */
	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	result = saAmfComponentRegister (&handle, &compName, NULL);
	pthread_create (&dispatch_thread, NULL, th_dispatch, &handle);
	sleep (10);
//	saAmfFinalize (&handle);

	exit (0);
}
void
clProxiedCompInstantiate(
    SaInvocationT       invocation,
    const SaNameT       *proxiedCompName)
{
    SaNameT appName;
    ClRcT               rc = SA_AIS_OK; 

    /*
     * Add code for proxied component instatiation below. 
     * The code is specific to proxied component being instantiated 
     * and is defined by the protocol/interface between proxy and 
     * proxied component.
     */

    /*
     * ---BEGIN_APPLICATION_CODE---
     */
    

    /*
     * ---END_APPLICATION_CODE---
     */

    /*
     * If the instantiation of the proxied component was successful,
     * then register the proxied component with the AMF.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, proxiedCompName, &appName)) != SA_AIS_OK) 
        goto errorexit;

    saAmfResponse(amfHandle, invocation, SA_AIS_OK);

    return;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return;
}
コード例 #9
0
ファイル: cpd_amf.c プロジェクト: indonexia2004/opensaf-indo
/****************************************************************************
 * Name          : cpd_amf_register
 *
 * Description   : CPD registers with AMF for involking process.
 *
 * Arguments     : cpd_cb  - Ifsv control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uint32_t cpd_amf_register(CPD_CB *cpd_cb)
{
	SaAisErrorT error;
	TRACE_ENTER();
	/* get the component name */
	error = saAmfComponentNameGet(cpd_cb->amf_hdl, &cpd_cb->comp_name);
	if (error != SA_AIS_OK) {
		LOG_ER("cpd amf compname get failed with Error: %u",error);
		TRACE_LEAVE();
		return NCSCC_RC_FAILURE;
	}

	if (saAmfComponentRegister(cpd_cb->amf_hdl, &cpd_cb->comp_name, (SaNameT *)NULL) == SA_AIS_OK) {
		TRACE_LEAVE2("cpd amf register success for %s",cpd_cb->comp_name.value);
		return NCSCC_RC_SUCCESS;
	} else {
		TRACE_LEAVE2("cpd Amf component register failed for %s",cpd_cb->comp_name.value);
		return NCSCC_RC_FAILURE;
	}
}
コード例 #10
0
ファイル: immd_amf.c プロジェクト: indonexia2004/opensaf-indo
/**
 * Thread start routine to register with AMF and start health check
 * Error handling: exits process at failure
 * @param __cb control block pointer
 */
static void* amf_init_start(void *notused)
{
	SaAisErrorT error;
	const char *health_key;
	SaAmfHealthcheckKeyT healthy;

	TRACE_ENTER();

	error = saAmfComponentRegister(immd_cb->amf_hdl, &immd_cb->comp_name, NULL);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfComponentRegister failed: %u, exiting", error);
		exit(1);
	}

	memset(&healthy, 0, sizeof(healthy));
	health_key = getenv("IMMSV_ENV_HEALTHCHECK_KEY");

	if (health_key == NULL) {
		strncpy((char *)healthy.key, "A1B2", sizeof(healthy.key));
		healthy.keyLen = (SaUint16T) strlen((char *)healthy.key);
	} else {
		healthy.keyLen = (SaUint16T) strlen((char *)health_key);
		if (healthy.keyLen < sizeof(healthy.key)) {
			strncpy((char *)healthy.key, health_key, sizeof(healthy.key));
		} else {
			LOG_ER("Health check key too long:%u, exiting", healthy.keyLen);
			exit(1);
		}
	}

	error = saAmfHealthcheckStart(immd_cb->amf_hdl, &immd_cb->comp_name,
		&healthy, SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_FAILOVER);

	if (error != SA_AIS_OK) {
		LOG_ER("saAmfHealthcheckStart failed: %u, exiting", error);
		exit(1);
	}

	TRACE_LEAVE();
	return NULL;
}
コード例 #11
0
/****************************************************************************
 * Name          : cpnd_amf_register
 *
 * Description   : CPND registers with AMF for involking process.
 *
 * Arguments     : cpnd_cb  - Ifsv control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uns32 cpnd_amf_register(CPND_CB *cpnd_cb)
{

	SaAisErrorT error;

	/* get the component name */
	error = saAmfComponentNameGet(cpnd_cb->amf_hdl, &cpnd_cb->comp_name);
	if (error != SA_AIS_OK) {
		m_LOG_CPND_CL(CPND_AMF_COMP_NAME_GET_FAILED, CPND_FC_HDLN, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}

	if (saAmfComponentRegister(cpnd_cb->amf_hdl, &cpnd_cb->comp_name, (SaNameT *)NULL) == SA_AIS_OK)
		return NCSCC_RC_SUCCESS;
	else {
		m_LOG_CPND_CL(CPND_AMF_COMP_REG_FAILED, CPND_FC_HDLN, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}

	m_LOG_CPND_CL(CPND_AMF_REGISTER_SUCCESS, CPND_FC_GENERIC, NCSFL_SEV_NOTICE, __FILE__, __LINE__);
}
コード例 #12
0
ClRcT initializeAmf()
{
   
    SaNameT             appName;      
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    
    version.releaseCode  = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;
    
    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = clEventTerminate;
    callbacks.saAmfCSISetCallback               = NULL;
    callbacks.saAmfCSIRemoveCallback            = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
    callbacks.saAmfProxiedComponentInstantiateCallback = NULL;
    callbacks.saAmfProxiedComponentCleanupCallback = NULL;

    clEoMyEoIocPortGet(&iocPort);
   
    rc = saAmfInitialize(&gClEvtAmfHandle, &callbacks, &version);
    if(rc != SA_AIS_OK)
    {
        clLogWrite(CL_LOG_HANDLE_APP, CL_LOG_CRITICAL, NULL,
                   CL_LOG_MESSAGE_2_LIBRARY_INIT_FAILED, "CPM Library", rc);
        return clSafToClovisError(rc);
    }

    rc = saAmfComponentNameGet(gClEvtAmfHandle, &appName);
    rc = saAmfComponentRegister(gClEvtAmfHandle, &appName, NULL);

    return CL_OK;
    
}
int main (int argc, char **argv) {
	int result;
	SaSelectionObjectT select_fd;
	fd_set read_fds;
	extern char *optarg;
	extern int optind;
	int c;

	memset (&compNameGlobal, 0, sizeof (SaNameT));
	signal (SIGINT, sigintr_handler);
#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
	result = sched_setscheduler (0, SCHED_RR, &sched_param);
	if (result == -1) {
		printf ("couldn't set sched priority\n");
 	}
#endif

	for (;;){
		c = getopt(argc,argv,"h:n:");
		if (c==-1) {
			break;
		}
		switch (c) {
		case 0 :
			break;
		case 'h':
			health_flag = 0;
			sscanf (optarg,"%ud" ,&healthcheck_count);
			break;
		case 'n':
	  		setSanameT (&compNameGlobal, optarg);
			break;
                default :
			break;
                }
	}

	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	if (result != SA_OK) {
		printf ("initialize result is %d\n", result);
		exit (1);
	}

	FD_ZERO (&read_fds);
	saAmfSelectionObjectGet (handle, &select_fd);
	FD_SET (select_fd, &read_fds);
	if (compNameGlobal.length <= 0) {
		setSanameT (&compNameGlobal, "comp_b_in_su_2");
	}

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);
	result = saAmfComponentRegister (handle, &compNameGlobal, NULL);
	printf ("register result is %d (should be 1)\n", result);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result && stop == 0);

	sleep (5);
	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result);

	saAmfFinalize (handle);

	exit (0);
}
コード例 #14
0
ファイル: gld_api.c プロジェクト: kenzaburo/OpenSaf-FrameWork
/****************************************************************************
 * Name          : gld_se_lib_init
 *
 * Description   : Invoked to Initialize the GLD
 *                 
 *
 * Arguments     : 
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE..
 *
 * Notes         : None.
 *****************************************************************************/
uns32 gld_se_lib_init(NCS_LIB_REQ_INFO *req_info)
{
	GLSV_GLD_CB *gld_cb;
	SaAisErrorT amf_error;
	uns32 res = NCSCC_RC_SUCCESS;
	SaAmfHealthcheckKeyT Healthy;
	int8 *health_key;

	/* Register with Logging subsystem */
	if (NCS_GLSV_LOG == 1)
		gld_flx_log_reg();

	/* Allocate and initialize the control block */
	gld_cb = m_MMGR_ALLOC_GLSV_GLD_CB;

	if (gld_cb == NULL) {
		m_LOG_GLD_MEMFAIL(GLD_CB_ALLOC_FAILED, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}
	memset(gld_cb, 0, sizeof(GLSV_GLD_CB));

	/* TBD- Pool id is to be set */
	gl_gld_hdl = gld_cb->my_hdl = ncshm_create_hdl(gld_cb->hm_poolid, NCS_SERVICE_ID_GLD, (NCSCONTEXT)gld_cb);
	if (0 == gld_cb->my_hdl) {
		m_LOG_GLD_HEADLINE(GLD_CREATE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize the cb parameters */
	if (gld_cb_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize amf framework */
	if (gld_amf_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}
	m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/* Bind to MDS */
	if (gld_mds_init(gld_cb) != NCSCC_RC_SUCCESS) {
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/*   Initialise with the MBCSV service  */
	if (glsv_gld_mbcsv_register(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;

	} else {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	}

	/* register glsv with imm */
	amf_error = gld_imm_init(gld_cb);
	if (amf_error != SA_AIS_OK) {
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		gld_log(NCSFL_SEV_ERROR, "Imm Init Failed %u\n", amf_error);
		return NCSCC_RC_FAILURE;
	}

	/* TASK CREATION AND INITIALIZING THE MAILBOX */
	if ((m_NCS_IPC_CREATE(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_IPC_ATTACH(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_CREATE((NCS_OS_CB)gld_main_process,
			       &gld_cb->mbx, "GLD", m_GLD_TASK_PRIORITY,
			       m_GLD_STACKSIZE,
			       &gld_cb->task_hdl) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_START(gld_cb->task_hdl) != NCSCC_RC_SUCCESS)) {
		m_LOG_GLD_HEADLINE(GLD_IPC_TASK_INIT, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return (NCSCC_RC_FAILURE);
	}

	m_NCS_EDU_HDL_INIT(&gld_cb->edu_hdl);

	/* register GLD component with AvSv */
	amf_error = saAmfComponentRegister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

   /** start the AMF health check **/
	memset(&Healthy, 0, sizeof(Healthy));
	health_key = (int8 *)getenv("GLSV_ENV_HEALTHCHECK_KEY");
	if (health_key == NULL) {
		if (strlen("A1B2") < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, "A1B2", sizeof(Healthy.key));
		m_LOG_GLD_HEADLINE(GLD_HEALTH_KEY_DEFAULT_SET, NCSFL_SEV_INFO, __FILE__, __LINE__, 0);
	} else {
		if (strlen((char *)health_key) < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, (char *)health_key, SA_AMF_HEALTHCHECK_KEY_MAX - 1);
	}
	Healthy.keyLen = strlen((char *)Healthy.key);

	amf_error = saAmfHealthcheckStart(gld_cb->amf_hdl, &gld_cb->comp_name, &Healthy,
					  SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_FAILOVER);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		saAmfComponentUnregister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_DONE, NCSFL_SEV_INFO, __FILE__, __LINE__);

	return (res);
}
void initializeAmf(void)
{
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    /* Get the pid for the process and store it in global variable. */
    mypid = getpid();

    /* SAFplus is fully API compatible with SA-Forum (SAF) definitions.

       This optional call customizes OpenClovis SAFplus Platform extensions
       to the basic SAF services (to use, you would define the parameters as globals).  
       
       If this call is removed, standard SAF services will work just fine. */

    /* clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs); */

    
    /*
     * Initialize and register with SAFplus AMF. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */
    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = safTerminate;
    callbacks.saAmfCSISetCallback               = safAssignWork;
    callbacks.saAmfCSIRemoveCallback            = safRemoveWork;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /* Initialize AMF client library. */
    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        errorExit(rc);

    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        errorExit(rc);
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        errorExit(rc);
    /* Open the log stream as soon as I've registered with AMF */
    clEvalAppLogStreamOpen((ClCharT *)appName.value, &gEvalLogStream);

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /* csa112: initialize the event client library, open the event channel and subscribe to events */
    if (1)
    {
        const SaEvtCallbacksT evtCallbacks =
        {
            NULL,  /* Event open callback */
            csa112Comp_appEventCallback  /* Event delivery callback */
        };
        SaVersionT  evtVersion = {(ClUint8T)'B', 0x1, 0x1};
        
        rc = saEvtInitialize(&evtLibHandle, &evtCallbacks, &evtVersion);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_SEV_ERROR, "Failed to init event mechanism [0x%x]\n", rc);
            return ;
        }
            // Open an event chanel so that we can subscribe to events on that channel
        rc = saEvtChannelOpen(evtLibHandle, &evtChannelName, (SA_EVT_CHANNEL_PUBLISHER | SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE), (SaTimeT)SA_TIME_END, &evtChannelHandle);
        if (rc != SA_AIS_OK)
          {
          clprintf(CL_LOG_SEV_ERROR, "Failure opening event channel [0x%x] at %ld", rc, time(0L));
          errorExit(rc);
          }
        
      rc = saEvtEventSubscribe(evtChannelHandle, NULL, 1);
      if (rc != SA_AIS_OK)
      {
        clprintf(CL_LOG_SEV_ERROR, "Failed to subscribe to event channel [0x%x]",rc);
         errorExit(rc);
      }
    }

    /*csa113: create an event definition to be published */
    if (1)
    {
        SaNameT publisherName;
        saNameSet((SaNameT*) &publisherName,PUBLISHER_NAME);
        
        rc = saEvtEventAllocate(evtChannelHandle, &eventHandle);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_SEV_ERROR, "Failed to allocate event [0x%x]\n", rc);
            assert(0);
        }

        rc = saEvtEventAttributesSet(eventHandle, NULL, 1, 0, &publisherName);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_SEV_ERROR, "Failed to set event attributes [0x%x]\n",rc);
            assert(0);            
        }
    }
}
コード例 #16
0
static PyObject* initializeAmf(PyObject *self, PyObject *args)
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    ClRcT               rc = SA_AIS_OK;    

    PyEval_InitThreads();    
    PyThreadState* pts = PyThreadState_Get();
    thePythonInterpreter = pts->interp;

    /* Put the EO name received from the environment in the appropriate variable */
    //strncpy(clEoConfig.EOname,getenv("ASP_COMPNAME"),CL_EO_MAX_NAME_LEN-1);
    
    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */

    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL;
    callbacks.saAmfComponentTerminateCallback   = clCompAppTerminate;
    callbacks.saAmfCSISetCallback               = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback            = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /*
     * Initialize AMF client library.
     */

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK) 
        goto errorexit;

    clprintf (CL_LOG_SEV_INFO, "AmfInitialize successful");

    if (1)
    {
        
    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
    {
        clprintf (CL_LOG_SEV_ERROR, "Error getting selection object -- unable to dispatch AMF events");
        return NULL;        
    }
    }
    
    /*
     * Do the application specific initialization here.
     */

    /*
     * ---BEGIN_APPLICATION_CODE---
     */

#if 0
    if (1)
      {
      void (*extensions[])(void) = { init_asp, initasppycustom, 0 };
      clPyGlueInit("clusterMgrApp",extensions);
      }
#endif

    /*
     * ---END_APPLICATION_CODE---
     */

    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    clprintf (CL_LOG_SEV_INFO, "component name get successful");

    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        goto errorexit;
    clprintf (CL_LOG_SEV_INFO, "component register successful");

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%s] : PID [%d]. Initializing\n", appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /*
     * ---BEGIN_APPLICATION_CODE---
     */
    //clPyGlueStart();
    /*
     * ---END_APPLICATION_CODE---
     */
    rc = clOsalTaskCreateDetached("AmfDispatcher",CL_OSAL_SCHED_OTHER, CL_OSAL_THREAD_PRI_NOT_APPLICABLE, 0, amfDispatcher,NULL);
    

errorexit:

    if (rc != CL_OK)
      {
        char str[256];
        snprintf(str,255,"Component [%s] : PID [%d]. Initialization error [0x%x]\n", appName.value, mypid, rc);
        clprintf (CL_LOG_SEV_ERROR, str);
        //return PyInt_FromLong(rc);
        PyObject* errData = Py_BuildValue("is",rc,str);
        PyErr_SetObject(PyExc_SystemError,errData);
        return NULL;     
      }
    Py_RETURN_NONE;
    }
コード例 #17
0
/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_ComponentRegistryImpl_registerProxiedComponent
 * TYPE:      native method
 *  Class:     ais_amf_ComponentRegistry
 *  Method:    registerProxiedComponent
 *  Signature: (Ljava/lang/String;)V
 *************************************************************************/
JNIEXPORT void JNICALL Java_org_opensaf_ais_amf_ComponentRegistryImpl_registerProxiedComponent(
    JNIEnv* jniEnv,
    jobject thisComponentRegistry,
    jstring proxiedComponentName )
{
    // VARIABLES
    SaNameT _saProxyComponentName;
    SaNameT _saProxiedComponentName;
    SaNameT* _saProxiedComponentNamePtr = &_saProxiedComponentName;
    SaAmfHandleT _saAmfHandle;
    SaAisErrorT _saStatus;
    // JNI
    jobject _amfLibraryHandle;
    jstring _thisComponentName;

    // BODY

    assert( thisComponentRegistry != NULL );
    _TRACE2( "NATIVE: Executing Java_org_opensaf_ais_amf_ComponentRegistryImpl_registerProxiedComponent(...)\n" );


    // get Java library handle
    _amfLibraryHandle = (*jniEnv)->GetObjectField( jniEnv,
                                                   thisComponentRegistry,
                                                   FID_amfLibraryHandle );

    assert( _amfLibraryHandle != NULL );

    // get native library handle
    _saAmfHandle = (SaAmfHandleT) (*jniEnv)->GetLongField( jniEnv,
                                                           _amfLibraryHandle,
                                                           FID_saAmfHandle );
    // get Java component name
    _thisComponentName = (*jniEnv)->GetObjectField( jniEnv,
                                                    thisComponentRegistry,
                                                    FID_componentName );
    // copy Java component name object
    if( JNU_copyFromStringToSaNameT_NotNull( jniEnv,
		                                     _thisComponentName,
        		                             &_saProxyComponentName ) != JNI_TRUE ){
        return; // EXIT POINT! Exception pending...
    }
    // copy Java proxied component name object
    if( JNU_copyFromStringToSaNameT( jniEnv,
                                     proxiedComponentName,
		                             &_saProxiedComponentNamePtr ) != JNI_TRUE ){
        return; // EXIT POINT! Exception pending...
    }

    // call saAmfComponentRegister
    _saStatus = saAmfComponentRegister( _saAmfHandle,
                                        _saProxiedComponentNamePtr,
                                        &_saProxyComponentName );

    _TRACE2( "NATIVE: saAmfComponentRegister(...) has returned with %d...\n", _saStatus );

    // error handling
    if( _saStatus != SA_AIS_OK ){
        switch( _saStatus ){
            case SA_AIS_ERR_LIBRARY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
            case SA_AIS_ERR_TIMEOUT:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTimeoutException",
                                    AIS_ERR_TIMEOUT_MSG );
                break;
            case SA_AIS_ERR_TRY_AGAIN:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisTryAgainException",
                                    AIS_ERR_TRY_AGAIN_MSG );
                break;
            case SA_AIS_ERR_BAD_HANDLE:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisBadHandleException",
                                    AIS_ERR_BAD_HANDLE_MSG );
                break;
            case SA_AIS_ERR_INIT:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisInitException",
                                    AIS_ERR_INIT_MSG );
                break;
            case SA_AIS_ERR_INVALID_PARAM:
            	// can happen if _saProxyComponentNamePtr is NULL
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisInvalidParamException",
                                    AIS_ERR_INVALID_PARAM_MSG );
                break;
            case SA_AIS_ERR_NO_MEMORY:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNoMemoryException",
                                    AIS_ERR_NO_MEMORY_MSG );
                break;
            case SA_AIS_ERR_NO_RESOURCES:
                JNU_throwNewByName( jniEnv,
                                    "ais/AisNoResourcesException",
                                    AIS_ERR_NO_RESOURCES_MSG );
                break;
            case SA_AIS_ERR_NOT_EXIST:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisNotExistException",
                                    AIS_ERR_NOT_EXIST_MSG );
                break;
            case SA_AIS_ERR_EXIST:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisExistException",
                                    AIS_ERR_EXIST_MSG );
                break;
            case SA_AIS_ERR_BAD_OPERATION:
                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisBadOperationException",
                                    AIS_ERR_BAD_OPERATION_MSG );
                break;
            default:
                // this should not happen here!

                assert( JNI_FALSE );

                JNU_throwNewByName( jniEnv,
                                    "org/saforum/ais/AisLibraryException",
                                    AIS_ERR_LIBRARY_MSG );
                break;
        }
        return; // EXIT POINT! Exception pending...
    }


    _TRACE2( "NATIVE: Java_org_opensaf_ais_amf_ComponentRegistryImpl_registerProxiedComponent(...) returning normally\n" );


}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd = 0;
    fd_set read_fds;
    
    /*
     * Declare other local variables here.
     */

    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */

    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL;
    callbacks.saAmfComponentTerminateCallback   = clCompAppTerminate;
    callbacks.saAmfCSISetCallback               = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback            = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /*
     * Initialize AMF client library.
     */

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK) 
        goto errorexit;


    /*
     * Do the application specific initialization here.
     */
    
    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        goto errorexit;

    /*
     * Initialize the log stream
     */
    clEvalAppLogStreamOpen((ClCharT*)appName.value, &gEvalLogStream);

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);


    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        struct timeval timeout;
        timeout.tv_sec = 2; timeout.tv_usec = 0;

        FD_ZERO(&read_fds);
        FD_SET(dispatch_fd, &read_fds);

        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, &timeout) < 0)
        {
            if (EINTR == errno)
            {
                continue;
            }
		    clprintf (CL_LOG_SEV_ERROR, "Error in select()");
			perror("");
            break;
        }
        if (FD_ISSET(dispatch_fd,&read_fds)) saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
        
        if (running) clprintf(CL_LOG_SEV_INFO,"csa102: Unthreaded Hello World! %s", show_progress());
        else clprintf(CL_LOG_SEV_INFO,"csa102: idle");        
    }while(!unblockNow);      

    /*
     * Do the application specific finalization here.
     */


    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
	{
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
	}

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");
    
    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
void initializeAmf(void)
{
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    /* Get the pid for the process and store it in global variable. */
    mypid = getpid();

    /* SAFplus is fully API compatible with SA-Forum (SAF) definitions.

       This optional call customizes OpenClovis SAFplus Platform extensions
       to the basic SAF services (to use, you would define the parameters as globals).  
       
       If this call is removed, standard SAF services will work just fine. */

    /* clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs); */

    
    /*
     * Initialize and register with SAFplus AMF. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */
    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = safTerminate;
    callbacks.saAmfCSISetCallback               = safAssignWork;
    callbacks.saAmfCSIRemoveCallback            = safRemoveWork;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /* Initialize AMF client library. */
    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        errorExit(rc);

    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        errorExit(rc);
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        errorExit(rc);

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    strncpy(appname, (ClCharT*)appName.value, sizeof(appname)-1);
 
    
    if ((rc = checkpoint_initialize()) != SA_AIS_OK)
    {
        clprintf(CL_LOG_SEV_ERROR,"%s: Failed [0x%x] to initialize checkpoint\n",appname, rc);
        errorExit(rc);
    }
    if ((rc = checkpoint_read_seq(&seq)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_SEV_ERROR,"%s: Failed [0x%x] to read checkpoint\n", appname, rc);
        checkpoint_finalize();
        errorExit(rc);
    }
#ifdef CL_INST
    if ((rc = clDataTapInit(DATA_TAP_DEFAULT_FLAGS, 203)) != CL_OK)
    {
        clprintf(CL_LOG_SEV_ERROR,"%s: Failed [0x%x] to initialize data tap\n", appname, rc);
    }
#endif
    clOsalTaskCreateDetached("testCkpMainLoop", CL_OSAL_SCHED_OTHER, CL_OSAL_THREAD_PRI_NOT_APPLICABLE, 65536, testCkpMainLoop, (void*)appname);
}
コード例 #20
0
ファイル: wrapper.c プロジェクト: helioloureiro/opensaf-fork
static SaAisErrorT amf_initialize(SaSelectionObjectT *amf_sel_obj)
{
	SaAisErrorT rc;
	SaAmfCallbacksT amf_callbacks = {0};
	SaVersionT api_ver =
		{.releaseCode = 'B', api_ver.majorVersion = 0x01, api_ver.minorVersion = 0x01};

	amf_callbacks.saAmfCSISetCallback = csi_set_callback;
	amf_callbacks.saAmfCSIRemoveCallback = csi_remove_callback;
	amf_callbacks.saAmfHealthcheckCallback = healthcheck_callback;
	amf_callbacks.saAmfComponentTerminateCallback = terminate_callback;

	rc = saAmfInitialize(&my_amf_hdl, &amf_callbacks, &api_ver);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, " saAmfInitialize FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfSelectionObjectGet(my_amf_hdl, amf_sel_obj);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfComponentNameGet(my_amf_hdl, &my_comp_name);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentNameGet FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfComponentRegister(my_amf_hdl, &my_comp_name, 0);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentRegister FAILED (%u)", rc);
		goto done;
	}
	
done:
	return rc;
}

int main(int argc, char **argv)
{
	SaAisErrorT rc;
	SaSelectionObjectT amf_sel_obj;
	struct pollfd fds[1];
	int logmask;

	if (daemon(0, 0) == -1) {
		syslog(LOG_ERR, "daemon failed: %s", strerror(errno));
		goto done;
	}

	create_pid_file();

	/* Cancel certain signals that would kill us */
	signal(SIGTERM, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGUSR1, SIG_IGN);
	signal(SIGUSR2, SIG_IGN);

	openlog(basename(argv[0]), LOG_PID, LOG_USER);

	// TBD: Configure logmask from args/vars
	logmask = LOG_UPTO(LOG_INFO);
//	setlogmask(logmask);

	start_script = getenv("STARTSCRIPT");
	if (start_script == NULL) {
		syslog(LOG_ERR, "Variable STARTCRIPT missing");
		goto done;
	}

	stop_script = getenv("STOPSCRIPT");
	if (stop_script == NULL) {
		syslog(LOG_ERR, "Variable STOPSCRIPT missing");
		goto done;
	}

	health_script = getenv("HEALTHCHECKSCRIPT");
	if (health_script == NULL) {
		syslog(LOG_ERR, "Variable HEALTHCHECKSCRIPT missing");
		goto done;
	}

	pidfile = getenv("PIDFILE");

	if (amf_initialize(&amf_sel_obj) != SA_AIS_OK)
		goto done;


	fds[0].fd = amf_sel_obj;
	fds[0].events = POLLIN;

	syslog(LOG_INFO, "'%s' started", getenv("SA_AMF_COMPONENT_NAME"));

	while (1) {
		int res = poll(fds, 1, -1);

		if (res == -1) {
			if (errno == EINTR)
				continue;
			else {
				syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
				goto done;
			}
		}

		if (fds[0].revents & POLLIN) {
			rc = saAmfDispatch(my_amf_hdl, SA_DISPATCH_ONE);
			if (rc != SA_AIS_OK) {
				syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
				goto done;
			}
		}
	}

done:
	return EXIT_FAILURE;
}
ClRcT clLogSvrInitialize(ClUint32T argc,ClCharT   *argv[])
{
    SaAmfCallbacksT     callbacks = {0};
    SaVersionT          version;
    
    ClRcT            rc            = CL_OK;
    ClBoolT          *pCookie      = NULL;
	
    clLogCompName =(ClCharT*) "LOG"; /* Override generated eo name with a short name for our server */
    gClLogServer = CL_FALSE;  /* Mark me as the log server */

    clLogInfo(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, "Log Server initialization started...");

    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);

    version.releaseCode  = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;

    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = clLogSvrTerminate;
    callbacks.saAmfCSISetCallback               = NULL;
    callbacks.saAmfCSIRemoveCallback            = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;        
    callbacks.saAmfProxiedComponentInstantiateCallback    = NULL;
    callbacks.saAmfProxiedComponentCleanupCallback    = NULL;

    rc = saAmfInitialize(&amfHandle, &callbacks, &version);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfInitialize(): rc[0x %x]", rc));
        return rc;
    }
          

    rc = saAmfComponentNameGet(amfHandle, &logServerName);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfComponentNameGet(): rc[0x %x]", rc));
        saAmfFinalize(amfHandle);
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }
    rc = saAmfComponentRegister(amfHandle, &logServerName, NULL);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfComponentRegister(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        saAmfFinalize(amfHandle);
        return rc;
    }   

    clLogNotice(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, "Log Server partially up");

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;					    
}
コード例 #22
0
ファイル: dts_amf.c プロジェクト: kenzaburo/OpenSaf-FrameWork
/**************************************************************************\
 Function: dts_amf_register

 Purpose:  Function which registers DTS with AMF.  

 Input:    None 

 Returns:  NCSCC_RC_SUCCESSS/NCSCC_RC_FAILURE

 Notes:  Here we call dts_amf_init after reading the component name file and
         setting the environment varaiable in our own context.
         Proceed to register with AMF, since it has come up. 
\**************************************************************************/
uns32 dts_amf_register(DTS_CB *inst)
{
	SaAisErrorT error;
	char comp_name[256] = { 0 };
	char compfilename[DTS_COMP_FILE_NAME_LEN] = { 0 };
	FILE *fp;

	m_DTS_LK(&inst->lock);
	m_LOG_DTS_LOCK(DTS_LK_LOCKED, &inst->lock);

	/* Read the component name file now, AMF should have populated it by now */
	assert(sprintf(compfilename, "%s", m_DTS_COMP_NAME_FILE) < sizeof(compfilename));

	fp = fopen(compfilename, "r");	/* PKGLOCALSTATEDIR/dts_comp_name */
	if (fp == NULL) {
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register:Unable to open file");
	}

	if (fscanf(fp, "%s", comp_name) != 1) {
		fclose(fp);
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register:Unable to retrieve component name");
	}

	if (setenv("SA_AMF_COMPONENT_NAME", comp_name, 1) == -1) {
		fclose(fp);
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
				      "dts_amf_register:Unable to set SA_AMF_COMPONENT_NAME enviroment variable");
	}
	fclose(fp);
	fp = NULL;

	if (NCSCC_RC_SUCCESS != dts_amf_init(inst)) {
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register: AMF Initialization failed.");
	}

	/* Get component name */
	error = saAmfComponentNameGet(inst->amf_hdl, &inst->comp_name);
	if (error != SA_AIS_OK) {
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register: Component name get failed.");

	}

	/* register DTS component with AvSv */
	error = saAmfComponentRegister(inst->amf_hdl, &inst->comp_name, (SaNameT *)NULL);
	if (error != SA_AIS_OK) {
		/* log the error */
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register: DTS AMF Component registration failed.");
	}

	if (NCSCC_RC_SUCCESS != dts_healthcheck_start(inst)) {
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_register: Health check start fail.");
	}

	m_LOG_DTS_API(DTS_AMF_INIT_SUCCESS);

	inst->amf_init = TRUE;

	m_DTS_UNLK(&inst->lock);
	m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);

	return NCSCC_RC_SUCCESS;
}
コード例 #23
0
ファイル: ntfs_amf.c プロジェクト: helioloureiro/opensaf-fork
/**************************************************************************
 Function: ntfs_amf_register

 Purpose:  Function which registers NTFS with AMF.  

 Input:    None 

 Returns:  SA_AIS_OK    - everything is OK
           SA_AIS_ERR_* -  failure

**************************************************************************/
SaAisErrorT ntfs_amf_init()
{
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT error = SA_AIS_OK;

	TRACE_ENTER();

	if (ntfs_cb->nid_started &&
		amf_comp_name_get_set_from_file("NTFD_COMP_NAME_FILE", &ntfs_cb->comp_name) != NCSCC_RC_SUCCESS)
		goto done;

	/* Initialize AMF callbacks */
	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));
	amfCallbacks.saAmfHealthcheckCallback = amf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = amf_csi_set_callback;
	amfCallbacks.saAmfComponentTerminateCallback = amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = amf_csi_rmv_callback;

	amf_version.releaseCode = 'B';
	amf_version.majorVersion = 0x01;
	amf_version.minorVersion = 0x01;

	/* Initialize the AMF library */
	error = saAmfInitialize(&ntfs_cb->amf_hdl, &amfCallbacks, &amf_version);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfInitialize() FAILED: %u", error);
		goto done;
	}

	/* Obtain the AMF selection object to wait for AMF events */
	error = saAmfSelectionObjectGet(ntfs_cb->amf_hdl, &ntfs_cb->amfSelectionObject);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfSelectionObjectGet() FAILED: %u", error);
		goto done;
	}

	/* Get the component name */
	error = saAmfComponentNameGet(ntfs_cb->amf_hdl, &ntfs_cb->comp_name);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfComponentNameGet() FAILED: %u", error);
		goto done;
	}

	/* Register component with AMF */
	error = saAmfComponentRegister(ntfs_cb->amf_hdl, &ntfs_cb->comp_name, (SaNameT *)NULL);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfComponentRegister() FAILED");
		goto done;
	}

	/* Start AMF healthchecks */
	if (ntfs_amf_healthcheck_start() != SA_AIS_OK){
		LOG_ER("ntfs_amf_healthcheck_start() FAILED");
		error = NCSCC_RC_FAILURE;
		goto done;
	}

 done:
	TRACE_LEAVE();
	return error;
}
コード例 #24
0
ファイル: amf_demo.c プロジェクト: helioloureiro/opensaf-fork
/**
 * Initialize with AMF
 * @param amf_sel_obj [out]
 * 
 * @return SaAisErrorT
 */
static SaAisErrorT amf_initialize(SaSelectionObjectT *amf_sel_obj)
{
	SaAisErrorT rc;
	SaAmfCallbacksT amf_callbacks = {0};
	SaVersionT api_ver =
		{.releaseCode = 'B', api_ver.majorVersion = 0x01, api_ver.minorVersion = 0x01};

	/* Initialize our callbacks */
	amf_callbacks.saAmfCSISetCallback = amf_csi_set_callback;
	amf_callbacks.saAmfCSIRemoveCallback = amf_csi_remove_callback;
	amf_callbacks.saAmfHealthcheckCallback = amf_healthcheck_callback;
	amf_callbacks.saAmfComponentTerminateCallback = amf_comp_terminate_callback;

	rc = saAmfInitialize(&my_amf_hdl, &amf_callbacks, &api_ver);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, " saAmfInitialize FAILED %u", rc);
		goto done;
	}

	rc = saAmfSelectionObjectGet(my_amf_hdl, amf_sel_obj);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED %u", rc);
		goto done;
	}

	rc = saAmfComponentNameGet(my_amf_hdl, &my_comp_name);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentNameGet FAILED %u", rc);
		goto done;
	}

	rc = saAmfComponentRegister(my_amf_hdl, &my_comp_name, 0);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentRegister FAILED %u", rc);
		goto done;
	}
	
	rc = saAmfHealthcheckStart(my_amf_hdl, &my_comp_name, &my_healthcheck_key,
		SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_RESTART);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfHealthcheckStart FAILED - %u", rc);
		goto done;
	}
done:
	return rc;
}

int main(int argc, char **argv)
{
	SaAisErrorT rc;
	SaSelectionObjectT amf_sel_obj;
	struct pollfd fds[1];
	char *env_comp_name;

	/* Environment variable "SA_AMF_COMPONENT_NAME" exist when started by AMF */
	if ((env_comp_name = getenv("SA_AMF_COMPONENT_NAME")) == NULL) {
		fprintf(stderr, "not started by AMF exiting...\n");
		exit(EXIT_FAILURE);
	}

	/* Daemonize ourselves and detach from terminal.
	** This important since our start script will hang forever otherwise.
	** Note daemon() is not LSB but impl by libc so fairly portable...
	*/
	if (daemon(0, 0) == -1) {
		syslog(LOG_ERR, "daemon failed: %s", strerror(errno));
		goto done;
	}

	/* Install a TERM handler just to log and visualize when cleanup is called */
	if ((signal(SIGTERM, sigterm_handler)) == SIG_ERR) {
		syslog(LOG_ERR, "signal TERM failed: %s", strerror(errno));
		goto done;
	}

	/* Create a PID file which is needed by our CLC-CLI script.
	** Use AMF component name as file name so multiple instances of this
	** component can be managed by the same script.
	*/
	create_pid_file("/tmp", env_comp_name);

	/* Use syslog for logging */
	openlog(basename(argv[0]), LOG_PID, LOG_USER);

	/* Make a log to associate component name with PID */
	syslog(LOG_INFO, "'%s' started", env_comp_name);

	if (amf_initialize(&amf_sel_obj) != SA_AIS_OK)
		goto done;

	syslog(LOG_INFO, "Registered with AMF and HC started");

	fds[0].fd = amf_sel_obj;
	fds[0].events = POLLIN;

	/* Loop forever waiting for events on watched file descriptors */
	while (1) {
		int res = poll(fds, 1, -1);

		if (res == -1) {
			if (errno == EINTR)
				continue;
			else {
				syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
				goto done;
			}
		}

		if (fds[0].revents & POLLIN) {
			/* An AMF event is received, call AMF dispatch which in turn will
			 * call our installed callbacks. In context of this main thread.
			 */
			rc = saAmfDispatch(my_amf_hdl, SA_DISPATCH_ONE);
			if (rc != SA_AIS_OK) {
				syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
				goto done;
			}
		}
	}

done:
	return EXIT_FAILURE;
}
コード例 #25
0
SaAisErrorT initializeAmf(void)
{
    SaAmfCallbacksT     callbacks;
   
    ClIocPortT          iocPort=0;
    SaAisErrorT         rc = SA_AIS_OK;
    /*This function overrides the default EO Configuaration */
    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);
    /*
     * Initialize and register with SAFplus AMF. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */
     /*
     * Set the supported version.
     */
     gVersion.releaseCode = 'B';
     gVersion.majorVersion = 0x01;
     gVersion.minorVersion = 0x01;
   
     /*
     * Fill the AMS's callback structure.
     */
     callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
     callbacks.saAmfComponentTerminateCallback   = ckptTerminate;
     callbacks.saAmfCSISetCallback               = NULL;
     callbacks.saAmfCSIRemoveCallback            = NULL;
     callbacks.saAmfProtectionGroupTrackCallback = NULL;
     
     /*
     * Get the port Id from IOC.
     */
     clEoMyEoIocPortGet(&iocPort);

     
        
     /* Initialize AMF client library. */
     rc = saAmfInitialize(&amfHandle, &callbacks, &gVersion);
       
     /*
     * Get the component name from AMF.
     */

     rc = saAmfComponentNameGet(amfHandle, &appName);
      /*
     * Initialize ckpt server.
     */

     clCkptLeakyBucketInitialize();

     clCkptSvrInitialize();
     

     rc = saAmfComponentRegister(amfHandle, &appName, NULL);
    
     gCkptSvr->amfHdl = amfHandle;

     /*
     * Obtain the component id from cpm. This will be used while registering
     * ckpt master address with TL.
     */
     clAmfGetComponentId(gCkptSvr->amfHdl, &appName, &gCkptSvr->compId);

     /*
     * Register with debug server.
     */
     ckptDebugRegister(gCkptSvr->eoHdl);
    
     return rc;
}
コード例 #26
0
/****************************************************************************
  Name          : avsv_amf_process

  Description   : This routine is an entry point for the AMF interface task.
		  It demonstrates the use of following AMF APIs
		  a) saAmfInitialize
		  b) saAmfSelectionObjectGet
		  c) saAmfCompNameGet
		  d) saAmfComponentRegister
		  e) saAmfDispatch

  Arguments     : None.

  Return Values : None.

  Notes         : None
******************************************************************************/
void *avsv_amf_process (void* dummy)
{
    SaAmfCallbacksT    reg_callback_set;
    SaVersionT         ver;
    SaAisErrorT        rc;
    SaSelectionObjectT amf_sel_obj;
    struct pollfd fds[1];

    syslog(LOG_INFO, " AMF thread entered");

    /*#########################################################################
    		  Demonstrating the use of saAmfInitialize()
    #########################################################################*/

    /* Fill the callbacks that are to be registered with AMF */
    memset(&reg_callback_set, 0, sizeof(SaAmfCallbacksT));
    reg_callback_set.saAmfCSISetCallback = avsv_amf_csi_set_callback;
    reg_callback_set.saAmfCSIRemoveCallback = avsv_amf_csi_remove_callback;
    reg_callback_set.saAmfHealthcheckCallback = avsv_amf_healthcheck_callback;
    reg_callback_set.saAmfComponentTerminateCallback = avsv_amf_comp_terminate_callback;
    reg_callback_set.saAmfProtectionGroupTrackCallback = avsv_amf_protection_group_callback;

    /* Fill the AMF version */
    m_AMF_VER_GET(ver);

    /* Initialize AMF */
    rc = saAmfInitialize(&gl_amf_hdl, &reg_callback_set, &ver);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, " saAmfInitialize FAILED %u", rc);
        goto done;
    }

    syslog(LOG_INFO, "AMF Initialization Done !!!");
    syslog(LOG_INFO, "\tAmfHandle: %llx ", gl_amf_hdl);

    /*#########################################################################
    	       Demonstrating the use of saAmfSelectionObjectGet()
    #########################################################################*/

    /* Get the selection object corresponding to this AMF handle */
    rc = saAmfSelectionObjectGet(gl_amf_hdl, &amf_sel_obj);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "AMF Selection Object Get Successful !!!");

    /*#########################################################################
    		Demonstrating the use of saAmfCompNameGet()
    #########################################################################*/

    rc = saAmfComponentNameGet(gl_amf_hdl, &gl_comp_name);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentNameGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Name Get Successful !!!");
    syslog(LOG_INFO, "\tCompName: %s", gl_comp_name.value);

    /*#########################################################################
    	      Demonstrating the use of saAmfComponentRegister()
    #########################################################################*/

    rc = saAmfComponentRegister(gl_amf_hdl, &gl_comp_name, 0);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentRegister FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Registered !!!");

    fds[0].fd = amf_sel_obj;
    fds[0].events = POLLIN;

    /***** Now wait on the AMF selection object *****/
    while (1) {
        int res = poll(fds, 1, -1);

        if (res == -1) {
            if (errno == EINTR)
                continue;
            else {
                syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
                exit(1);
            }
        }

        /*######################################################################
        		Demonstrating the use of saAmfDispatch()
        ######################################################################*/

        if (fds[0].revents & POLLIN) {
            /* There is an AMF callback waiting to be be processed. Process it */
            rc = saAmfDispatch(gl_amf_hdl, SA_DISPATCH_ONE);
            if (SA_AIS_OK != rc) {
                syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
                saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
                saAmfFinalize(gl_amf_hdl);
                break;
            }
        }
    }

    syslog(LOG_INFO, "DEMO OVER !!!");
done:
    return NULL;
}
コード例 #27
0
/****************************************************************************
  Name          : pxy_pxd_amf_process
 
  Description   : This routine is an entry point for the AMF interface task.
                  It demonstrates the use of following AMF APIs
                  a) saAmfInitialize
                  b) saAmfSelectionObjectGet
                  c) saAmfCompNameGet
                  d) saAmfComponentRegister
                  e) saAmfDispatch
 
  Arguments     : None.
 
  Return Values : None.
 
  Notes         : None
******************************************************************************/
void pxy_pxd_amf_process (void)
{
   SaAisErrorT        rc;
   NCS_SEL_OBJ_SET    wait_sel_objs, all_sel_objs;
   SaSelectionObjectT pxy_amf_sel_obj,pxd_amf_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        pxy_amf_ncs_sel_obj,pxd_amf_ncs_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        highest_sel_obj,wait_sel_fd;
   int ret = 0;
   uns32 comp_inv_hc_time_out = 500;
   uns32 index = 0;

   /* this is to allow to establish MDS session with AvSv */
   m_NCS_TASK_SLEEP(3000);

   pxy_pxd_proxy_initialize();   

   rc = pxy_pxd_proxy_amf_init();

   if (SA_AIS_OK != rc)
      return;
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     rc = pxy_pxd_proxied_amf_init(index);

   if (SA_AIS_OK != rc)
      return;

   /* Get the selection object corresponding to this AMF handle */
   rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxy_info.amfHandle, &pxy_amf_sel_obj);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }
   
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
     /* Get the selection object corresponding to this AMF handle */
     rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                  &pxd_amf_sel_obj[index]);
     if (SA_AIS_OK != rc)
     {
       saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
       printf("\n AMF Selection Object Get Failed for index %d !!!\n",index);
       return;
     }
   }

   printf("\n AMF Selection Object Get Successful !!! \n");

   rc = saAmfComponentNameGet(pxy_pxd_cb.pxy_info.amfHandle, 
                                 &pxy_pxd_cb.pxy_info.compName);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Component Name Get Successful !!! \n CompName: %s \n",
                      pxy_pxd_cb.pxy_info.compName.value);


   rc = saAmfComponentRegister(pxy_pxd_cb.pxy_info.amfHandle, 
                               &pxy_pxd_cb.pxy_info.compName, 0);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Proxy Component Registered !!! \n");

   /* Reset the wait select objects */
   m_NCS_SEL_OBJ_ZERO(&all_sel_objs);

   m_SET_FD_IN_SEL_OBJ((uns32)pxy_amf_sel_obj, pxy_amf_ncs_sel_obj);
   m_NCS_SEL_OBJ_SET(pxy_amf_ncs_sel_obj, &all_sel_objs);
   highest_sel_obj = pxy_amf_ncs_sel_obj;

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    m_SET_FD_IN_SEL_OBJ((uns32)pxd_amf_sel_obj[index], pxd_amf_ncs_sel_obj[index]);
    m_NCS_SEL_OBJ_SET(pxd_amf_ncs_sel_obj[index], &all_sel_objs);
    highest_sel_obj = m_GET_HIGHER_SEL_OBJ(highest_sel_obj, pxd_amf_ncs_sel_obj[index]);
   }

   wait_sel_objs = all_sel_objs;
   wait_sel_fd  = highest_sel_obj;

   /* Now wait forever */
   while ((ret = m_NCS_SEL_OBJ_SELECT(wait_sel_fd, &wait_sel_objs, NULL, NULL,
           &comp_inv_hc_time_out)) != -1)
   {
    comp_inv_hc_time_out = 500;
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxy_amf_ncs_sel_obj, &wait_sel_objs))
    {
      printf("\n Got Proxy AMF event!!! \n");
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxy_info.amfHandle, SA_DISPATCH_ALL);
      if (SA_AIS_OK != rc)
      {
         printf("\n Proxy saAmfDispatch failed !!! \n");
         break;
      }
    }
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    if(TRUE == pxy_pxd_cb.pxd_info[index].reg_pxied_comp)
    {
      printf("\n Before registering pxd[%d]!!!\n",index);
      /* Need to register proxied component */
      rc = saAmfComponentRegister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                   &pxy_pxd_cb.pxd_info[index].compName,
                                   &pxy_pxd_cb.pxy_info.compName);
      if (SA_AIS_OK == rc)
      {
        printf("\n Proxied[%d] Component Registeration Successful. "
                              "Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].health_start = TRUE;
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
      else if (SA_AIS_ERR_TRY_AGAIN == rc)
      {
        printf("\n Proxied[%d] Component Registeration failed. TRY_AGAIN"
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
      }
      else
      {
        printf("\n Proxied[%d] Component Registeration failed."
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
     }
    } /* if(TRUE == pxy_pxd_cb.reg_pxied_comp) */

   /* Section 1 Starts : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */
   {
    SaAmfHealthcheckInvocationT    hc_inv;
    SaAmfRecommendedRecoveryT      rec_rcvr;

     for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     {
       if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)
       { 
        printf("\n Before registering hc [%d]!!!\n",index);
        hc_inv = SA_AMF_HEALTHCHECK_AMF_INVOKED;
        rec_rcvr = SA_AMF_COMPONENT_FAILOVER;

        rc = saAmfHealthcheckStart(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                   &pxy_pxd_cb.pxd_info[index].compName, 
                                   &pxy_pxd_cb.pxd_info[index].healthcheck_key,
                                   hc_inv, rec_rcvr);
        if (SA_AIS_OK == rc )
        {
          printf("Started AMF-Initiated HealthCheck (with Component "
                          "Failover Recommended Recovery) \n Comp: %s \n" 
                          "HealthCheckKey: %s \n",
                          pxy_pxd_cb.pxd_info[index].compName.value, 
                          pxy_pxd_cb.pxd_info[index].healthcheck_key.key);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
          pxy_pxd_cb.pxd_info[index].health_start_comp_inv = TRUE;   
        }
        else if(SA_AIS_ERR_TRY_AGAIN == rc)
        {
          printf(" AMF-Initiated HealthCheck TRY_AGAIN (with Component"
                            " Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
        }
        else
        {
          printf(" AMF-Initiated HealthCheck failed (with Component "
                            "Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
        }
       } /* if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)*/ 
     }
   }
   /* Section 1 Ends : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */

  if(TRUE == pxy_pxd_cb.unreg_pxied_comp)
  {
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
      printf("\n Before unregistering PXD[%d]!!! \n",index);
      /* Need to unregister proxied component */
       rc = saAmfComponentUnregister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                     &pxy_pxd_cb.pxd_info[index].compName,
                                     &pxy_pxd_cb.pxy_info.compName);
       if (SA_AIS_OK != rc)
       {
          printf("\n Proxied Component unreg failed. Comp %s, Pxy Comp %s, Res %d\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value,rc);
       }
       else
          printf("\n Proxied Component unreg Succ. Comp %s, Pxy Comp %s\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value);
       pxy_pxd_cb.unreg_pxied_comp = FALSE;
       pxy_pxd_cb.pxd_info[index].health_start_comp_inv = FALSE;
   }
  }

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxd_amf_ncs_sel_obj[index], &wait_sel_objs))
    {
      printf("\n Before Pxd dispatch PXD[%d] !!!\n",index);
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxd_info[index].amfHandle, SA_DISPATCH_ONE);
      if (SA_AIS_OK != rc)
      {
         printf("\n PXD[%d] saAmfDispatch failed !!! \n",index);
         break;
      }
    }
   }
      /* Again set AMF select object to wait for another callback */
      wait_sel_objs = all_sel_objs;
      wait_sel_fd  = highest_sel_obj;
   }/* While loop */

   printf("\n\n Proxy Exited, ret %d!!!\n\n",ret);

   return;
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;
    
    /*
     * Declare other local variables here.
     */

    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */

    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL;
    callbacks.saAmfComponentTerminateCallback   = clCompAppTerminate;
    callbacks.saAmfCSISetCallback               = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback            = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /*
     * Initialize AMF client library.
     */

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK) 
        goto errorexit;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        goto errorexit;
    
    FD_SET(dispatch_fd, &read_fds);


    /*
     * Do the application specific initialization here.
     */


    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        goto errorexit;

    /* Open the log stream as soon as I've registered with AMF */
    clEvalAppLogStreamOpen((ClCharT *)appName.value, &gEvalLogStream);

    /* Handle the AMF dispatch loop by spawning a thread that does it */
    rc = clOsalTaskCreateDetached("DISPATCH-THREAD", CL_OSAL_SCHED_OTHER, 0, 0, saAmfDispatchThread, NULL);
    if(rc != CL_OK)
    {
        clprintf(CL_LOG_SEV_ERROR, "Dispatch task create failed with rc 0x%x",rc);
        return rc;
    }
    
    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /* csa112: initialize the event client library, open the event channel and subscribe to events */
    if (1)
    {
        const SaEvtCallbacksT evtCallbacks =
        {
            NULL,  /* Event open callback */
            csa112Comp_appEventCallback  /* Event delivery callback */
        };
        SaVersionT  evtVersion = {(ClUint8T)'B', 0x1, 0x1};
        
        rc = saEvtInitialize(&evtLibHandle, &evtCallbacks, &evtVersion);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_ERROR, "Failed to init event mechanism [0x%x]\n", rc);
            return rc;
        }
            // Open an event chanel so that we can subscribe to events on that channel
        rc = saEvtChannelOpen(evtLibHandle, &evtChannelName, (SA_EVT_CHANNEL_PUBLISHER | SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE), (SaTimeT)SA_TIME_END, &evtChannelHandle);
        if (rc != SA_AIS_OK)
          {
          clprintf(CL_LOG_SEV_ERROR, "Failure opening event channel [0x%x] at %ld", rc, time(0L));
          goto errorexit;
          }
        
      rc = saEvtEventSubscribe(evtChannelHandle, NULL, 1);
      if (rc != SA_AIS_OK)
      {
        clprintf(CL_LOG_SEV_ERROR, "Failed to subscribe to event channel [0x%x]",rc);
        goto errorexit;
      }
    }

    /*csa113: create an event definition to be published */
    if (1)
    {
        SaNameT publisherName;
        clNameSet((ClNameT*) &publisherName,PUBLISHER_NAME);
        
        rc = saEvtEventAllocate(evtChannelHandle, &eventHandle);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_SEV_ERROR, "Failed to allocate event [0x%x]\n", rc);
            assert(0);
        }

        rc = saEvtEventAttributesSet(eventHandle, NULL, 1, 0, &publisherName);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_ERROR, "Failed to set event attributes [0x%x]\n",rc);
            assert(0);            
        }
    }
    
    
    while (!exiting)
    {
        /* csa112: If I am active then I'll publish an event.
           Note, any application can publish and event regardless of
           HA state.  This tutorial simply uses HA state so only
           one of the two processes are publishing.
        */
        
    if (running && ha_state == SA_AMF_HA_ACTIVE)
    {
        csa113Comp_PublishEvent();
    }
    
    sleep(1);  /* Keep the event publish rate reasonable for this tutorial*/
    }
    
    /*
     * Do the application specific finalization here.
     */

    /* csa112: close the event channel, finalize the event client library */
    if ((rc = saEvtChannelClose(evtChannelHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_ERROR, "Failed [0x%x] to close event channel", rc);
    }

    if ((rc = saEvtFinalize(evtLibHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_ERROR, "Failed [0x%x] to finalize event library", rc);
    }

    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
	{
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
	}

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");
    
    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;

    /*
     * Declare other local variables here.
     */


    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the version of
     * AMF with which this application would like to interface. 'callbacks'
     * is used to register the callbacks this component expects to receive.
     */

    version.releaseCode                         = 'B';
    version.majorVersion                        = 01;
    version.minorVersion                        = 01;

    callbacks.saAmfHealthcheckCallback                    = NULL;
    callbacks.saAmfComponentTerminateCallback             = clCompAppTerminate;
    callbacks.saAmfCSISetCallback                         = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback                      = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback           = NULL;
    callbacks.saAmfProxiedComponentInstantiateCallback    = clProxiedCompInstantiate;
    callbacks.saAmfProxiedComponentCleanupCallback        = clProxiedCompCleanup;

    /*
     * Get IOC Address, Port and Name. Register with AMF.
     */

    clEoMyEoIocPortGet(&iocPort);

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        goto errorexit;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        goto errorexit;

    FD_SET(dispatch_fd, &read_fds);

    /*
     * Do the application specific initialization here.
     */


    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK)
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK)
        goto errorexit;

    /*
     * Print out standard information for this component.
     */

    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
            clprintf (CL_LOG_SEV_ERROR, "Error in select()");
            perror("");
            break;
        }
        saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
    } while(!unblockNow);

    /*
     * Do the application specific finalization here.
     */


    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
    {
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    }

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");

    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
ClRcT 
clLogSvrInitialize(ClUint32T argc,ClCharT   *argv[])
{
    SaAmfCallbacksT     callbacks = {0};
    SaVersionT          version;
    
    ClRcT            rc            = CL_OK;
    ClLogSvrEoDataT  *pSvrEoEntry  = NULL;
    ClBoolT          *pCookie      = NULL;
    ClIocAddressT    invalidAddr   = {{0}};
	
    clLogCompName =(ClCharT*) "LOG"; /* Override generated eo name with a short name for our server */
    gClLogServer = CL_FALSE;  /* Mark me as the log server */

    clLogInfo(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, "Log Server initialization started...");

    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);

    version.releaseCode  = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;

    callbacks.saAmfHealthcheckCallback          = NULL; /* rarely necessary because SAFplus monitors the process */
    callbacks.saAmfComponentTerminateCallback   = clLogSvrTerminate;
    callbacks.saAmfCSISetCallback               = NULL;
    callbacks.saAmfCSIRemoveCallback            = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;        
    callbacks.saAmfProxiedComponentInstantiateCallback    = NULL;
    callbacks.saAmfProxiedComponentCleanupCallback    = NULL;

    rc = saAmfInitialize(&amfHandle, &callbacks, &version);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfInitialize(): rc[0x %x]", rc));
        return rc;
    }
          

#if defined(CL_DEBUG) && defined(CL_DEBUG_START)
    clLogDebugLevelSet();
#endif
    CL_LOG_DEBUG_TRACE(("Enter"));	

    clLogSvrMutexModeSet();
    
    /* 
     * Here dummy initialization of Idl handle to avoid mutiple database 
     * Initialization & finalization databases. Keeping this handle alive 
     * will avoid this. coz Idl library will delete the handle database if the
     * handle count becomes zero. Mutiple times we are initializing & deleting
     * the handles in our log service usage.
    */
    rc = clLogIdlHandleInitialize(invalidAddr, &shLogDummyIdl);
    if( CL_OK != rc )
    {
        
        return rc;
    }
    rc = clLogSvrCommonDataInit();
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrCommonDataInit(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }
    rc = clLogStreamOwnerLocalBootup();
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogStreamOwnerLocalInit(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }    
    pCookie = (ClBoolT*) clHeapCalloc(1, sizeof(ClBoolT));
    if( NULL == pCookie )
    {
        CL_LOG_DEBUG_ERROR(("clHeapCalloc()"));
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return CL_LOG_RC(CL_ERR_NO_MEMORY);
    }
    *pCookie = CL_FALSE;
    rc = clLogSvrBootup(pCookie);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrDataInit(): rc[0x %x]", rc));
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }    
    clLogInfo(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, 
              "Log server boot type is [%s]", 
              (*pCookie == 1)? "Restart": "Normal");

    rc = clLogSvrEoEntryGet(&pSvrEoEntry, NULL);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }
    pSvrEoEntry->hCpm = amfHandle;
    rc = saAmfComponentNameGet(amfHandle, &logServerName);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfComponentNameGet(): rc[0x %x]", rc));
        saAmfFinalize(amfHandle);
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        return rc;
    }
    rc = saAmfComponentRegister(amfHandle, &logServerName, NULL);
    if( SA_AIS_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("saAmfComponentRegister(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        saAmfFinalize(amfHandle);
        return rc;
    }   
    pSvrEoEntry->hTimer = CL_HANDLE_INVALID_VALUE;
    if( CL_FALSE == *pCookie )
    {
        rc = clLogSvrTimerDeleteNStart(pSvrEoEntry, pCookie);
    }
    else
    {
        rc = clLogTimerCallback((void *) pCookie);
    }
    if( CL_OK != rc )
    {
        saAmfComponentUnregister(amfHandle, &logServerName, NULL);
        CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
        clHeapFree(pCookie);
        CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
        CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
        CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
        CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);
        saAmfFinalize(amfHandle);
        return rc;
    }
    rc = clLogDebugRegister();
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogDebugRegister(): rc[0x %x]", rc));
    }
    clLogNotice(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED, 
                "Log Server partially up");

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;					    
}