void saImmOiSelectionObjectGet_02(void) { safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK); rc = saImmOiSelectionObjectGet(-1, &selectionObject); test_validate(rc, SA_AIS_ERR_BAD_HANDLE); safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); }
static void *implementer_thread(void *arg) { struct pollfd fd[1]; SaSelectionObjectT selObject; int ret; SaAisErrorT err; SaImmOiHandleT immOiHandle = *(SaImmOiHandleT *)arg; safassert(saImmOiSelectionObjectGet(immOiHandle, &selObject), SA_AIS_OK); fd[0].fd = (int)selObject; fd[0].events = POLLIN; isReady = 1; while(1) { ret = poll(fd, 1, 1000); if(ret == 1) if((err = saImmOiDispatch(immOiHandle, SA_DISPATCH_ONE)) != SA_AIS_OK) break; } isOiDone = 1; return NULL; }
void SaImmOiRtAttrUpdateCallbackT_01(void) { SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT) __FUNCTION__; SaImmAdminOwnerNameT admoName = (SaImmAdminOwnerNameT) implementerName; struct pollfd fds[1]; int ret; pthread_t thread; TRACE_ENTER(); setup(admoName); immOiCallbacks.saImmOiRtAttrUpdateCallback = saImmOiRtAttrUpdateCallback; safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK); safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); safassert(saImmOiClassImplementerSet(immOiHandle, className), SA_AIS_OK); safassert(saImmOiSelectionObjectGet(immOiHandle, &selectionObject), SA_AIS_OK); ret = pthread_create(&thread, NULL, test_saImmOmAccessorGet_2, &testObjectName); assert(ret == 0); fds[0].fd = (int) selectionObject; fds[0].events = POLLIN; ret = poll(fds, 1, 1000); assert(ret == 1); safassert(saImmOiDispatch(immOiHandle, SA_DISPATCH_ONE), SA_AIS_OK); pthread_join(thread, NULL); test_validate(SA_AIS_OK, SA_AIS_OK); safassert(saImmOiClassImplementerRelease(immOiHandle, className), SA_AIS_OK); safassert(saImmOiImplementerClear(immOiHandle), SA_AIS_OK); safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); immOiCallbacks.saImmOiRtAttrUpdateCallback = NULL; tearDown(); TRACE_LEAVE(); }
SaAisErrorT immoi_initialize(SaImmHandleT *immOiHandle,SaSelectionObjectT * immOiSelectionObject){ SaVersionT immVersion = { 'A', 2, 1 }; SaAisErrorT rc; int retry = 3; //for the retry while(retry>0) { rc = saImmOiInitialize_2(immOiHandle, &immOiCallbacks, &immVersion); if (rc == SA_AIS_OK) { rc = saImmOiSelectionObjectGet(*immOiHandle, immOiSelectionObject); if (rc == SA_AIS_OK) { break; }else{ immoi_finalize(*immOiHandle); } } retry--; usleep(300); } if (rc != SA_AIS_OK) { syslog(LOG_ERR, "immoi_initialize FAILED: %d", rc); } return rc; }
/** * Initialize the OI interface, get a selection object and become applier * * @global_param max_waiting_time_ms: Wait max time for each operation. * @global_param applier_name: The name of the "configuration change" applier * @param *cb[out] * * @return (-1) if init fail */ int ntfimcn_imm_init(ntfimcn_cb_t *cb) { SaAisErrorT rc; int internal_rc = 0; int msecs_waited; TRACE_ENTER(); /* * Set IMM environment variable for synchronous timeout to 1 sec */ setenv("IMMA_SYNCR_TIMEOUT","100",1); /* * Initialize the IMM OI API * ------------------------- */ msecs_waited = 0; rc = saImmOiInitialize_2(&cb->immOiHandle, &callbacks, &imm_version); while ((rc == SA_AIS_ERR_TRY_AGAIN) && (msecs_waited < max_waiting_time_60s)) { usleep(sleep_delay_ms * 1000); msecs_waited += sleep_delay_ms; rc = saImmOiInitialize_2(&cb->immOiHandle, &callbacks, &imm_version); } if (rc != SA_AIS_OK) { LOG_ER("%s saImmOiInitialize_2 failed %s",__FUNCTION__,saf_error(rc)); internal_rc = NTFIMCN_INTERNAL_ERROR; goto done; } /* * Get a selection object for the IMM OI * ------------------------------------- */ msecs_waited = 0; rc = saImmOiSelectionObjectGet(cb->immOiHandle, &cb->immSelectionObject); while ((rc == SA_AIS_ERR_TRY_AGAIN) && (msecs_waited < max_waiting_time_60s)) { usleep(sleep_delay_ms * 1000); msecs_waited += sleep_delay_ms; rc = saImmOiSelectionObjectGet(cb->immOiHandle, &cb->immSelectionObject); } if (rc != SA_AIS_OK) { LOG_ER("%s saImmOiSelectionObjectGet failed %s",__FUNCTION__,saf_error(rc)); internal_rc = NTFIMCN_INTERNAL_ERROR; goto done; } /* * Become the "configuration change" applier * ----------------------------------------- */ SaImmOiImplementerNameT applier_name = applier_nameA; msecs_waited = 0; rc = saImmOiImplementerSet(cb->immOiHandle, applier_name); while (((rc == SA_AIS_ERR_TRY_AGAIN) || (rc == SA_AIS_ERR_EXIST)) && (msecs_waited < max_waiting_time_60s)) { usleep(sleep_delay_ms * 1000); msecs_waited += sleep_delay_ms; if (rc == SA_AIS_ERR_EXIST) { if (strcmp( applier_name, applier_nameA) == 0) { applier_name = applier_nameB; } else { applier_name = applier_nameA; } } rc = saImmOiImplementerSet(cb->immOiHandle, applier_name); } if (rc != SA_AIS_OK) { LOG_ER("%s Becoming an applier failed %s",__FUNCTION__,saf_error(rc)); internal_rc = NTFIMCN_INTERNAL_ERROR; goto done; } /* * Initialize the IMM OM API * ------------------------- */ msecs_waited = 0; rc = saImmOmInitialize(&cb->immOmHandle, &omCallbacks, &imm_version); while ((rc == SA_AIS_ERR_TRY_AGAIN) && (msecs_waited < max_waiting_time_60s)) { usleep(sleep_delay_ms * 1000); msecs_waited += sleep_delay_ms; rc = saImmOmInitialize(&cb->immOmHandle, &omCallbacks, &imm_version); } if (rc != SA_AIS_OK) { LOG_ER("%s saImmOmInitialize failed %s",__FUNCTION__,saf_error(rc)); internal_rc = NTFIMCN_INTERNAL_ERROR; goto done; } done: TRACE_LEAVE(); return internal_rc; }