/*----------------------------------------------- ** north_lbg_alloc ** create a Transaction context ** That function tries to allocate a free PDP ** context. In case of success, it returns the ** index of the Transaction context. ** @param : recli index @param relayCref : RELAY-C ref of the context @retval : MS controller reference (if OK) @retval NULL if out of context. */ north_lbg_ctx_t *north_lbg_alloc() { north_lbg_ctx_t *p; /* ** Get the first free context */ if ((p = (north_lbg_ctx_t*) ruc_objGetFirst((ruc_obj_desc_t*) north_lbg_context_freeListHead)) == (north_lbg_ctx_t*) NULL) { /* ** out of Transaction context descriptor try to free some MS ** context that are out of date */ severe( "NOT ABLE TO GET an AF_UNIX CONTEXT" ); return NULL; } /* ** reinitilisation of the context */ north_lbg_ctxInit(p, FALSE); /* ** remove it for the linked list */ north_lbg_context_allocated++; p->free = FALSE; ruc_objRemove((ruc_obj_desc_t*) p); /* ** insert in the active list the new element created */ ruc_objInsertTail((ruc_obj_desc_t*) & north_lbg_context_activeListHead, (ruc_obj_desc_t*) p); return p; }
/*---------------------------------------------- ** Declare a server **---------------------------------------------- ** IN : ** . name : name of the server ** . nbEvent : number of events generated ** by the server ** ** OUT : Server reference or -1 **----------------------------------------------- */ uint32_t ruc_observer_declareServer(char * name, uint32_t nbEvent) { RUC_OBSERVER_SERVER_T * pSrv; uint32_t idx; if (ruc_observer_initDone == FALSE) { ERRFAT "OBSERVER not initialised" ENDERRFAT; return -1; } /* ** get the first element from the free list */ pSrv = (RUC_OBSERVER_SERVER_T*)ruc_objGetFirst((ruc_obj_desc_t*) ruc_observer_server_freeListHead); if (pSrv == (RUC_OBSERVER_SERVER_T* )NULL) { ERRFAT "Out of server context" ENDERRFAT; return -1; } /* ** remove the context from the free list */ ruc_objRemove(&pSrv->link); /* ** store the callback pointer,the user Reference and priority */ strncpy(pSrv->name,name,RUC_OBSERVER_NAME_MAX); pSrv->name[RUC_OBSERVER_NAME_MAX-1] = 0; pSrv->nbEvent = nbEvent; /* ** Allocate an event table */ pSrv->pEventTbl = (RUC_OBSERVER_EVENT_T *)malloc(nbEvent*sizeof(RUC_OBSERVER_EVENT_T)); if (pSrv->pEventTbl == (RUC_OBSERVER_EVENT_T*)NULL) { /* ** out of memory */ ERRFAT "Out of memory" ENDERRFAT; return -1; } /* ** initialize each event */ for (idx=0; idx < nbEvent; idx++) { pSrv->pEventTbl[idx].event = idx; pSrv->pEventTbl[idx].pnextCur = NULL; ruc_listHdrInit(&pSrv->pEventTbl[idx].head); } /* ** insert in the server active list */ ruc_objInsertTail(&ruc_observer_server_activeList.link, &pSrv->link); return (pSrv->ref); }
/** geo_proc_alloc create a Transaction context That function tries to allocate a free PDP context. In case of success, it returns the index of the Transaction context. @param : rnone @retval : <>NULL: pointer to the allocated context @retval NULL if out of context. */ geo_proc_ctx_t *geo_proc_alloc() { geo_proc_ctx_t *p; /* ** Get the first free context */ if ((p = (geo_proc_ctx_t*) ruc_objGetFirst((ruc_obj_desc_t*) geo_proc_context_freeListHead)) == (geo_proc_ctx_t*) NULL) { /* ** out of Transaction context descriptor try to free some MS ** context that are out of date */ GEO_CTX_STATS(GEO_CTX_NO_CTX_ERROR); severe( "out of context" ); return NULL; } /* ** reinitilisation of the context */ geo_proc_ctxInit(p, FALSE); p->local_ref.s.timestamp = geo_srv_timestamp_get(); p->local_ref.s.index = p->index; if (p->record_buf_p != NULL) { free(p->record_buf_p); p->record_buf_p = NULL; } /* ** remove it for the linked list */ geo_proc_context_allocated++; p->free = FALSE; ruc_objRemove((ruc_obj_desc_t*) p); return p; }
return -1; } /* ** check that the event is not out of range */ if (event >= pSrv->nbEvent) { ERRLOG "Event is out of range: %d. Max is %u for %s",event, pSrv->nbEvent, pSrv->name ENDERRLOG return -1; } /* ** get the first element from the free list */ pClt = (RUC_OBSERVER_CLIENT_T*)ruc_objGetFirst((ruc_obj_desc_t*) ruc_observer_client_freeListHead); if (pClt == (RUC_OBSERVER_CLIENT_T* )NULL) { ERRLOG "No more free client" ENDERRLOG return -1; } /* ** remove the context from the free list */ ruc_objRemove(&pClt->link); /* ** store the callback pointer,the user Reference and priority */ pClt->srvRef = pSrv->ref; pClt->objRef = userRef; pClt->callBack = cbk;
/*---------------------------------------------- ** geo_ctx_tmr_processSlot **---------------------------------------------- ** ** It performs ** ** ** IN : ** ** OUT : none ** **----------------------------------------------- */ void geo_ctx_tmr_processSlot(ruc_obj_desc_t* pTmrQueue) { int32_t credit; geo_ctx_tmr_cell_t * p_refTim; uint32_t cur_date_s; uint8_t expired = FALSE; /* ** processing credit and date initialization */ credit = geo_ctx_tmr.credit; cur_date_s = geo_ctx_time(); /* ** process elements while there is still credit, ** and while time-out date is passed, ** and while there are still some elements */ while ( ((p_refTim=(geo_ctx_tmr_cell_t *)ruc_objGetFirst(pTmrQueue)) != (geo_ctx_tmr_cell_t *)NULL) && (credit > 0) ) { /* ** evaluate delay up to time out. ** if time out not yet passed, stop read queue */ expired = FALSE; while (1) { if (cur_date_s > p_refTim->date_s) { /* ** it is possible that the counter has wrapped */ if ((GEO_CTX_TIMER_MAX_DATE - cur_date_s + p_refTim->date_s) < p_refTim->delay) { /* ** nothing to do */ break; } expired = TRUE; break; } if (cur_date_s == p_refTim->date_s) { expired = TRUE; break; } if (cur_date_s < p_refTim->date_s) { /* ** no expiration but look at the delay request since ** if somebody has changed the data we can be out of ** sync */ if ((p_refTim->date_s - cur_date_s) > p_refTim->delay) { /* ** readjust the expiration date */ p_refTim->date_s = cur_date_s + p_refTim->delay; } } break; } if (!expired) { /* ** not expiration leaves the loop */ return; } /* ** timer cell dequeing from its current queue */ ruc_objRemove((ruc_obj_desc_t *)p_refTim); /* ** call the time-out function */ (*(p_refTim->p_callBack))(p_refTim->cBParam); credit--; } return; }