コード例 #1
0
ファイル: dts_amf.c プロジェクト: kenzaburo/OpenSaf-FrameWork
/****************************************************************************
 * Name          : dts_amf_init
 *
 * Description   : DTS initializes AMF for involking process and registers 
 *                 the various callback functions.
 *
 * Arguments     : dts_cb_inst  - DTS control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : Changed the function to do intialize of callbacks & selection 
 *                 objects. Called from dts_amf_register. 
 *****************************************************************************/
uns32 dts_amf_init(DTS_CB *dts_cb_inst)
{
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT error;

	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));

	amfCallbacks.saAmfHealthcheckCallback = dts_saf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = dts_saf_CSI_set_callback;
	amfCallbacks.saAmfCSIRemoveCallback = dts_saf_CSI_rem_callback;
	amfCallbacks.saAmfComponentTerminateCallback = dts_saf_comp_terminate_callback;

	m_DTS_GET_AMF_VER(amf_version);

	error = saAmfInitialize((SaAmfHandleT *)&dts_cb_inst->amf_hdl, &amfCallbacks, &amf_version);

	if (error != SA_AIS_OK) {
		/* Log */
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_init: DTS AMF Initialization fails.");
	}

	/* get the communication Handle */
	error = saAmfSelectionObjectGet(dts_cb_inst->amf_hdl, &dts_cb_inst->dts_amf_sel_obj);
	if (error != SA_AIS_OK) {
		/* log the error */
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_init: DTS AMF get selection object get failed.");
	}

	return (NCSCC_RC_SUCCESS);
}
コード例 #2
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);
}
コード例 #3
0
/****************************************************************************
  Name          : pxy_pxd_proxy_amf_init

  Description   : This routine initializes amf interface.

  Arguments     : None.

  Return Values : SUCC/FAILURE

  Notes         : None.
******************************************************************************/
uns32 pxy_pxd_proxy_amf_init(void)
{
   SaAisErrorT        rc;
   SaAmfCallbacksT    reg_callback_set;
   SaVersionT         ver;

   /* Fill the callbacks that are to be registered with AMF */
   memset(&reg_callback_set, 0, sizeof(SaAmfCallbacksT));
   reg_callback_set.saAmfCSISetCallback = proxy_csi_set_callback;
   reg_callback_set.saAmfCSIRemoveCallback = proxy_csi_remove_callback;
   reg_callback_set.saAmfHealthcheckCallback = proxy_healthcheck_callback;
   reg_callback_set.saAmfComponentTerminateCallback = proxy_comp_terminate_callback;
   reg_callback_set.saAmfProtectionGroupTrackCallback = proxy_comp_pg_callback;

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

   /* Initialize AMF */
   rc = saAmfInitialize(&pxy_pxd_cb.pxy_info.amfHandle, &reg_callback_set, &ver);
   if (SA_AIS_OK != rc)
   {
      printf("\n Proxy AMF Initialization Failed !!! \n AmfHandle: %lld \n", 
                       pxy_pxd_cb.pxy_info.amfHandle);
      return rc;
   }

   printf("\n Proxy AMF Initialization Done !!! \n AmfHandle: %lld \n", 
                       pxy_pxd_cb.pxy_info.amfHandle);
   return rc;

}
コード例 #4
0
/****************************************************************************
  Name          : pxy_pxd_proxied_amf_init

  Description   : This routine initializes amf interface for proxied comp.

  Arguments     : None.

  Return Values : None.

  Notes         : None.
******************************************************************************/
uns32 pxy_pxd_proxied_amf_init(uns32 index)
{
   SaAisErrorT        rc;
   SaAmfCallbacksT    reg_callback_set;
   SaVersionT         ver;

   /* Fill the callbacks that are to be registered with AMF */
   memset(&reg_callback_set, 0, sizeof(SaAmfCallbacksT));


   reg_callback_set.saAmfCSISetCallback = proxied_csi_set_callback;
   reg_callback_set.saAmfCSIRemoveCallback = proxied_csi_remove_callback;
   reg_callback_set.saAmfHealthcheckCallback = proxied_healthcheck_callback;
   reg_callback_set.saAmfComponentTerminateCallback = proxied_comp_terminate_callback;
   reg_callback_set.saAmfProxiedComponentInstantiateCallback = 
                                           proxied_comp_instantiate_callback;
    reg_callback_set.saAmfProxiedComponentCleanupCallback = 
                                           proxied_comp_cleanup_callback;

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

   /* Initialize AMF */
   rc = saAmfInitialize(&pxy_pxd_cb.pxd_info[index].amfHandle, &reg_callback_set, &ver);
   if (SA_AIS_OK != rc)
   {
      printf("\n Proxied[%d] AMF Initialization Failed !!! \n AmfHandle: %lld \n", 
                       index,pxy_pxd_cb.pxd_info[index].amfHandle);
      return rc;
   }
   printf("\n Proxied[%d] AMF Initialization Done !!! \n AmfHandle: %lld \n", 
                     index,pxy_pxd_cb.pxd_info[index].amfHandle);

   return rc;
}
コード例 #5
0
ファイル: cpd_amf.c プロジェクト: indonexia2004/opensaf-indo
/****************************************************************************
 * Name          : cpd_amf_init
 *
 * Description   : CPD initializes AMF for involking process and registers 
 *                 the various callback functions.
 *
 * Arguments     : cpd_cb  - CPD control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uint32_t cpd_amf_init(CPD_CB *cpd_cb)
{
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT error;
	uint32_t res = NCSCC_RC_SUCCESS;

	TRACE_ENTER();
	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));

	amfCallbacks.saAmfHealthcheckCallback = cpd_saf_hlth_chk_cb;
	amfCallbacks.saAmfCSISetCallback = cpd_saf_csi_set_cb;
	amfCallbacks.saAmfComponentTerminateCallback = cpd_amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = cpd_amf_csi_rmv_callback;

	m_CPSV_GET_AMF_VER(amf_version);

	error = saAmfInitialize(&cpd_cb->amf_hdl, &amfCallbacks, &amf_version);

	if (error != SA_AIS_OK) {
		LOG_ER("saAmfInitialize failed with Error:%u",error);
		res = NCSCC_RC_FAILURE;
	}
	if (error == SA_AIS_OK)
		TRACE_2("cpd amf init success");

	TRACE_LEAVE();
	return (res);
}
コード例 #6
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;
}
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);
}
コード例 #8
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);
}
コード例 #9
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);
}
コード例 #10
0
ファイル: plms_amf.c プロジェクト: helioloureiro/opensaf-fork
/****************************************************************************
 * Name          : plms_amf_init
 *
 * Description   : PLMS initializes AMF for invoking process and registers 
 *                 the various callback functions.
 *
 * Arguments     : PLMS_CB - PLMS control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/Error Code.
 *
 * Notes         : None.
 *****************************************************************************/
SaUint32T plms_amf_init()
{
	PLMS_CB * cb = plms_cb;
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	uint32_t rc = NCSCC_RC_SUCCESS;

	TRACE_ENTER();

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

	/* Initialize amf callbacks */
	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));

	amfCallbacks.saAmfHealthcheckCallback = plms_amf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = plms_amf_CSI_set_callback;
	amfCallbacks.saAmfComponentTerminateCallback = plms_amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = plms_amf_csi_rmv_callback;

	m_PLMS_GET_AMF_VER(amf_version);

	/*Initialize the amf library */

	rc = saAmfInitialize(&cb->amf_hdl, &amfCallbacks, &amf_version);

	if (rc != SA_AIS_OK) {
		LOG_ER("  plms_amf_init: saAmfInitialize() AMF initialization FAILED\n");
		goto done;
	}
	LOG_IN("  plms_amf_init: saAmfInitialize() AMF initialization SUCCESS\n");

	/* Obtain the amf selection object to wait for amf events */
	if (SA_AIS_OK != (rc = saAmfSelectionObjectGet(cb->amf_hdl, &cb->amf_sel_obj))) {
		LOG_ER("saAmfSelectionObjectGet() FAILED\n");
		goto done;
	}
	LOG_IN("saAmfSelectionObjectGet() SUCCESS\n");

	/* get the component name */

	rc = saAmfComponentNameGet(cb->amf_hdl, &cb->comp_name);
	if (rc != SA_AIS_OK) {
		LOG_ER("  plmss_amf_init: saAmfComponentNameGet() FAILED\n");
		goto done ;
	}

	rc = NCSCC_RC_SUCCESS;
done:
        TRACE_LEAVE2("%u, %s", rc, cb->comp_name.value);
        return rc;

}	/*End plms_amf_init */
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);
}
コード例 #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;
    
}
コード例 #13
0
/****************************************************************************
 * Name          : cpnd_amf_init
 *
 * Description   : CPND initializes AMF for involking process and registers 
 *                 the various callback functions.
 *
 * Arguments     : cpnd_cb  - Ifsv control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uns32 cpnd_amf_init(CPND_CB *cpnd_cb)
{
	SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT error;
	uns32 res = NCSCC_RC_SUCCESS;

	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));
	amfCallbacks.saAmfHealthcheckCallback = (SaAmfHealthcheckCallbackT)cpnd_saf_health_chk_callback;
	amfCallbacks.saAmfCSISetCallback = cpnd_saf_csi_set_cb;
	amfCallbacks.saAmfComponentTerminateCallback = cpnd_amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = (SaAmfCSIRemoveCallbackT)cpnd_amf_csi_rmv_callback;

	m_CPSV_GET_AMF_VER(amf_version);

	error = saAmfInitialize(&cpnd_cb->amf_hdl, &amfCallbacks, &amf_version);

	if (error != SA_AIS_OK) {
		m_LOG_CPND_CL(CPND_AMF_INIT_FAILED, CPND_FC_HDLN, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		res = NCSCC_RC_FAILURE;
	}
	return (res);
}
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);
}
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;					    
}
コード例 #16
0
ClRcT initializeAmf(void)
{
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClRcT	        rc = CL_OK;

    clLogCompName = (ClCharT*)"GMS"; /* Override generated eo name with a short name for our server */
    /* this function overrides the default EO configuration */
    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs); 

    /*  Do the CPM client init/Register */
    version.releaseCode  = 'B';
    version.majorVersion = 0x01;
    version.minorVersion = 0x01;
    
    callbacks.saAmfHealthcheckCallback          = NULL; 
    callbacks.saAmfComponentTerminateCallback   = clGmsServerTerminate;
    callbacks.saAmfCSISetCallback               = NULL;
    callbacks.saAmfCSIRemoveCallback            = NULL;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;

    gmsGlobalInfo.opState = CL_GMS_STATE_STARTING_UP;

    clLog(INFO,GEN,NA,
            CL_GMS_SERVER_STARTED);
        
    /* Initialize AMF client library. */
    rc = saAmfInitialize(&amfHandle, &callbacks, &version);
    if(rc!= SA_AIS_OK)
    {
        clLog(EMER,GEN,NA,
                "Sa AMF initialization Failed with rc [0x%x]. Booting Aborted",rc);
        exit(0);
        
    }
    gmsGlobalInfo.cpmHandle=amfHandle;
    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    rc = saAmfComponentNameGet(amfHandle, &appName);
    if(rc != SA_AIS_OK)
    {
         clLog(EMER,GEN,NA,
                "saAmfomponentNameGet Failed with rc [0x%x]. Booting Aborted",rc);
        exit(0);
      
    }
    gmsGlobalInfo.gmsComponentName.length=appName.length;
    memcpy(gmsGlobalInfo.gmsComponentName.value,appName.value,appName.length);

    rc = clEoMyEoObjectGet(&gmsGlobalInfo.gmsEoObject);
    if (rc != CL_OK)
    {
        clLog(EMER,GEN,NA,
               "clEoMyEoObjectGet Failed with rc [0x%x]. Booting Aborted",rc);
        exit(0);
    }
    
    rc = clDebugPromptSet(GMS_COMMAND_PROMPT);
    if( CL_OK == rc )
    {
        clLog(NOTICE,GEN,NA,
            "GMS Server registering with debug service");
        rc = clDebugRegister(
                gmsCliCommandsList, 
                (int)(sizeof(gmsCliCommandsList)/sizeof(ClDebugFuncEntryT)), 
                &gGmsDebugReg);
    }
    if( rc != CL_OK )
    {
        clLog(ERROR,GEN,NA,
            "Failed to register with debug server, error [0x%x]. Debug shell access disabled",
            rc);
    }

    rc = clEoClientInstallTables (
            gmsGlobalInfo.gmsEoObject,
            CL_EO_SERVER_SYM_MOD(gAspFuncTable, GMS));

    if ( rc != CL_OK )
    {
        clLog (EMER,GEN,NA,
                "Eo client install failed with rc [0x%x]. Booting aborted",rc);
        exit(0);
    }

    /* This function never returns the exit is done by causing a signal from
     *  the Terminate function */
   return CL_OK;
    
}
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;					    
}
コード例 #18
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;
}
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
ファイル: 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;
}
コード例 #21
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;
}
コード例 #22
0
ファイル: immd_amf.c プロジェクト: indonexia2004/opensaf-indo
/****************************************************************************
 * Name          : amf_init
 *
 * Description   : Initialize AMF for involking process and register
 *                 the various callback functions.
 *
 * Arguments     : immd_cb  - IMMD control block pointer.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uint32_t immd_amf_init(IMMD_CB *immd_cb)
{
	static SaAmfCallbacksT amfCallbacks;
	SaVersionT amf_version;
	SaAisErrorT error;
	uint32_t res = NCSCC_RC_FAILURE;
	pthread_t thread;
	pthread_attr_t attr;

	TRACE_ENTER();

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

	memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));

	amfCallbacks.saAmfHealthcheckCallback = immd_saf_hlth_chk_cb;
	amfCallbacks.saAmfCSISetCallback = immd_saf_csi_set_cb;
	amfCallbacks.saAmfComponentTerminateCallback = immd_amf_comp_terminate_callback;
	amfCallbacks.saAmfCSIRemoveCallback = immd_amf_csi_rmv_callback;

	m_IMMSV_GET_AMF_VER(amf_version);

	/*
	 * Perform the non blocking part of initialization.
	 * If the AMF implementation of these calls would change and become
	 * synchronous, this code would have to be changed too.
	 */
	error = saAmfInitialize(&immd_cb->amf_hdl, &amfCallbacks, &amf_version);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfInitialize failed");
		goto done;
	}

	error = saAmfComponentNameGet(immd_cb->amf_hdl, &immd_cb->comp_name);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfComponentNameGet failed");
		goto done;
	}

	error = saAmfSelectionObjectGet(immd_cb->amf_hdl, &immd_cb->amf_sel_obj);
	if (error != SA_AIS_OK) {
		LOG_ER("saAmfSelectionObjectGet failed");
		goto done;
	}

	/* Start a thread to take care of the blocking part of initialization */
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

	if (pthread_create(&thread, &attr, amf_init_start, NULL) != 0) {
		LOG_ER("pthread_create FAILED: %s", strerror(errno));
		goto done;
	}

	pthread_attr_destroy(&attr);

	res = NCSCC_RC_SUCCESS;

 done:
	TRACE_LEAVE2("%u, %s", res, osaf_extended_name_borrow(&immd_cb->comp_name));
	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);            
        }
    }
}
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;
}
コード例 #25
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;
}
コード例 #26
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;
}
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;
}
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;
}
コード例 #29
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;
    }