void tet_saEvtEventUnsubscribe(SaEvtChannelHandleT *ptrChannelHandle) { static int try_again_count; gl_rc=saEvtEventUnsubscribe(*ptrChannelHandle,gl_subscriptionId); WHILE_TRY_AGAIN(gl_rc) { ++try_again_count; if(try_again_count==MAX_NUM_TRY_AGAINS) { printf("\n Unsubscribe API Crossed Max Try Agains: exiting \n"); break; } RETRY_SLEEP; gl_rc=saEvtEventUnsubscribe(*ptrChannelHandle,gl_subscriptionId); if(gl_rc==SA_AIS_OK) printf("\n Event UnSubscribe Try Again Count = %d\n",try_again_count); } resultSuccess("saEvtEventUnsubscribe() invoked",gl_rc); }
int main(int argc, char **argv) { int ioc_address_local = LOCAL_ADDRESS; ClRcT rc = CL_OK; rc = clExtInitialize(ioc_address_local); if (rc != CL_OK) { printf("Error: failed to Initialize SAFplus libraries\n"); exit(1); } nodeCacheWait(); // Demonstrate logging */ printf("\n\nOpen a global log stream and write several records to active PY node\n"); if ((rc=logInitialize()) == CL_OK) { printf("log Initialized\n"); logWrite(CL_LOG_SEV_NOTICE,"This is a test of an external app doing logging"); for(int i=0;i<100;i++) { ClTimerTimeOutT delay; delay.tsSec = 0; delay.tsMilliSec = 10; logWrite(CL_LOG_SEV_NOTICE,"external app log %d", i); clOsalTaskDelay(delay); } } else { printf("Unable to open log. Error 0x%x\n",rc); return rc; } // Open a subscribe event channel and start receiving events. printf("\n\nOpen an Event subscription\n"); const SaEvtCallbacksT evtCallbacks = { NULL, appEventCallback }; SaVersionT evtVersion = CL_EVENT_VERSION; rc = saEvtInitialize(&evtHandle, &evtCallbacks, &evtVersion); if (rc != SA_AIS_OK) { printf("Failed to init event mechanism [0x%x]\n",rc); return rc; } saNameSet(&evtChannelName,EVENT_CHANNEL_NAME); rc = saEvtChannelOpen(evtHandle,&evtChannelName, (SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE), (SaTimeT)SA_TIME_END, &evtChannelHandle); if (rc != SA_AIS_OK) { printf("Failure opening event channel[0x%x] at %ld\n", rc, time(0L)); goto errorexit; } rc = saEvtEventSubscribe(evtChannelHandle, NULL, 1); if (rc != SA_AIS_OK) { printf("Failed to subscribe to event channel [0x%x]\n", rc); goto errorexit; } //open a global log stream and write several records printf("Open a publisher event channel\n"); // open a publisher event channel and openPublisherChannel(); printf("Start publishing events.\nThe PY component on active PY node subscribes to these events and logs them so you can verify receipt by looking in the clock.log.latest and app.lates on node active PY node .\n"); testEvtMainLoop(); printf("Unsubscribe event chanel.............................\n"); rc = saEvtEventUnsubscribe(evtChannelHandle,1); if (rc != SA_AIS_OK) printf("Channel unsubscribe result: %d\n", rc); printf("Close subscribe event chanel.............................\n"); rc = saEvtChannelClose(evtChannelHandle); if (rc != SA_AIS_OK) printf("Channel close result: %d\n", rc); printf("Close publish event channel.............................\n"); rc = saEvtChannelClose(evtChannelHandlePublic); if (rc != SA_AIS_OK) printf("Channel close result: %d\n", rc); // never inited: printf("Finalize publish event handle.............................\n"); // saEvtFinalize(gTestInfo.evtInitHandle); printf("Finalize xubscribe event handle.............................\n"); saEvtFinalize(evtHandle); openPublisherChannel(); testEvtMainLoop(); printf("Close publish event channel.............................\n"); rc = saEvtChannelClose(evtChannelHandlePublic); if (rc != SA_AIS_OK) printf("Channel close result: %d\n", rc); // never inited printf("Finalize publish event handle.............................\n"); // saEvtFinalize(gTestInfo.evtInitHandle); return 0; errorexit: printf ("Initialization error [0x%x]\n",rc); }