//-------------------------------------------------------------------------------------------------- static WatchdogObj_t* CreateNewWatchdog ( pid_t clientPid, ///< The process id of the client uid_t appId ///< the user id of the client ) { char timerName[LIMIT_MAX_TIMER_NAME_BYTES]; LE_DEBUG("Making a new dog"); WatchdogObj_t* newDogPtr = le_mem_ForceAlloc(WatchdogPool); newDogPtr->procId = clientPid; newDogPtr->appId = appId; newDogPtr->kickTimeoutInterval = GetConfigKickTimeoutInterval(clientPid, appId); LE_ASSERT(0 <= snprintf(timerName, sizeof(timerName), "wdog_u%d:p%d", clientPid, appId)); newDogPtr->timer = le_timer_Create(timerName); _Static_assert (sizeof(pid_t) <= sizeof(intptr_t), "pid_t is truncated by cast to void*"); LE_ASSERT(LE_OK == le_timer_SetContextPtr(newDogPtr->timer, (void*)((intptr_t)clientPid))); LE_ASSERT(LE_OK == le_timer_SetHandler(newDogPtr->timer, WatchdogHandleExpiry)); return newDogPtr; }
//-------------------------------------------------------------------------------------------------- ni_IteratorRef_t ni_CreateIterator ( le_msg_SessionRef_t sessionRef, ///< [IN] The user session this request occured on. tu_UserRef_t userRef, ///< [IN] Create the iterator for this user. tdb_TreeRef_t treeRef, ///< [IN] The tree to create the iterator with. ni_IteratorType_t type, ///< [IN] The type of iterator we are creating, read or write? const char* initialPathPtr ///< [IN] The node to move to in the specified tree. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(treeRef != NULL); // Allocate the object and setup it's initial properties. ni_IteratorRef_t iteratorRef = le_mem_ForceAlloc(IteratorPoolRef); iteratorRef->creationTime = le_clk_GetRelativeTime(); iteratorRef->sessionRef = sessionRef; iteratorRef->userRef = userRef; iteratorRef->treeRef = treeRef; iteratorRef->type = type; iteratorRef->reference = NULL; iteratorRef->isClosed = false; iteratorRef->isTerminated = false; // Setup the timeout timer for this transaction, if it's been configured. time_t configTimeout = ic_GetTransactionTimeout(); if (configTimeout > 0) { le_clk_Time_t timeout = { configTimeout, 0 }; iteratorRef->timerRef = le_timer_Create("Transaction Timer"); LE_ASSERT(le_timer_SetInterval(iteratorRef->timerRef, timeout) == LE_OK); LE_ASSERT(le_timer_SetHandler(iteratorRef->timerRef, OnTransactionTimeout) == LE_OK); LE_ASSERT(le_timer_SetContextPtr(iteratorRef->timerRef, iteratorRef) == LE_OK); LE_ASSERT(le_timer_Start(iteratorRef->timerRef) == LE_OK); } else { iteratorRef->timerRef = NULL; } // If this is a write iterator, then shadow the tree instead of accessing it directly. if (iteratorRef->type == NI_WRITE) { iteratorRef->treeRef = tdb_ShadowTree(iteratorRef->treeRef); } // Get the root node of the requested tree, or if this is a write iterator... Get the shadowed // root node of the tree. iteratorRef->currentNodeRef = tdb_GetRootNode(iteratorRef->treeRef); iteratorRef->pathIterRef = le_pathIter_CreateForUnix("/"); LE_DEBUG("Created a new %s iterator object <%p> for user %u (%s) on tree %s.", TypeString(type), iteratorRef, tu_GetUserId(userRef), tu_GetUserName(userRef), tdb_GetTreeName(treeRef)); // If we were given an initial path, go to it now. Otherwise stay on the root node. if (initialPathPtr) { ni_GoToNode(iteratorRef, initialPathPtr); } // Update the tree so that it can keep track of this iterator. tdb_RegisterIterator(treeRef, iteratorRef); // All done. return iteratorRef; }
static int mqttClient_startSession(mqttClient_t* clientData) { int rc = LE_OK; LE_ASSERT(clientData); memcpy(&clientData->session.config, &clientData->config, sizeof(clientData->config)); clientData->session.connTimer = le_timer_Create(MQTT_CLIENT_CONNECT_TIMER); if (!clientData->session.connTimer) { LE_ERROR("le_timer_Create() failed"); rc = LE_BAD_PARAMETER; goto cleanup; } rc = le_timer_SetHandler(clientData->session.connTimer, mqttClient_connExpiryHndlr); if (rc) { LE_ERROR("le_timer_SetHandler() failed(%d)", rc); goto cleanup; } rc = le_timer_SetMsInterval(clientData->session.connTimer, MQTT_CLIENT_CONNECT_TIMEOUT_MS); if (rc) { LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc); goto cleanup; } rc = le_timer_SetContextPtr(clientData->session.connTimer, clientData); if (rc) { LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc); goto cleanup; } clientData->session.cmdTimer = le_timer_Create(MQTT_CLIENT_COMMAND_TIMER); if (!clientData->session.cmdTimer) { LE_ERROR("le_timer_Create() failed"); rc = LE_BAD_PARAMETER; goto cleanup; } rc = le_timer_SetHandler(clientData->session.cmdTimer, mqttClient_cmdExpiryHndlr); if (rc) { LE_ERROR("le_timer_SetHandler() failed(%d)", rc); goto cleanup; } rc = le_timer_SetMsInterval(clientData->session.cmdTimer, MQTT_CLIENT_CMD_TIMEOUT_MS); if (rc) { LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc); goto cleanup; } rc = le_timer_SetContextPtr(clientData->session.cmdTimer, clientData); if (rc) { LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc); goto cleanup; } clientData->session.pingTimer = le_timer_Create(MQTT_CLIENT_PING_TIMER); if (!clientData->session.pingTimer) { LE_ERROR("le_timer_Create() failed"); rc = LE_BAD_PARAMETER; goto cleanup; } rc = le_timer_SetHandler(clientData->session.pingTimer, mqttClient_pingExpiryHndlr); if (rc) { LE_ERROR("le_timer_SetHandler() failed(%d)", rc); goto cleanup; } rc = le_timer_SetMsInterval(clientData->session.pingTimer, clientData->session.config.keepAlive * 1000); if (rc) { LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc); goto cleanup; } rc = le_timer_SetRepeat(clientData->session.pingTimer, 0); if (rc) { LE_ERROR("le_timer_SetRepeat() failed(%d)", rc); goto cleanup; } rc = le_timer_SetContextPtr(clientData->session.pingTimer, clientData); if (rc) { LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc); goto cleanup; } LE_INFO("connect(%s:%d)", clientData->session.config.brokerUrl, clientData->session.config.portNumber); rc = mqttClient_connect(clientData); if (rc) { LE_ERROR("mqttClient_connect() failed(%d)", rc); goto cleanup; } cleanup: if (rc) { LE_INFO("start session failed"); mqttClient_SendConnStateEvent(false, rc, -1); } return rc; }