diff --git a/include/rbus.h b/include/rbus.h index 8925dce7..89659ac2 100644 --- a/include/rbus.h +++ b/include/rbus.h @@ -131,23 +131,7 @@ typedef enum _rbusError RBUS_ERROR_DIRECT_CON_NOT_EXIST /**< Direct connection not exist */ } rbusError_t; -int rbusConfig_Init(rbusHandle_t handle); -int rbusConfig_Destroy(rbusHandle_t handle); -int rbusConfig_ReadGetTimeout(rbusHandle_t handle); -int rbusConfig_ReadWildcardGetTimeout(rbusHandle_t handle); -int rbusConfig_ReadSetTimeout(rbusHandle_t handle); -int rbusConfig_ReadSetMultiTimeout(rbusHandle_t handle); -int rbusConfig_ReadValueChangePeriod(rbusHandle_t handle); -int rbusConfig_ReadSubscribeTimeout(rbusHandle_t handle); -int rbusConfig_ReadSubscribeMaxWait(rbusHandle_t handle); - -int rbusConfig_UpdateSetTimeout(rbusHandle_t handle,int timeout); -int rbusConfig_UpdateGetTimeout(rbusHandle_t handle,int timeout); -int rbusConfig_UpdateWildcardGetTimeout(rbusHandle_t handle, int timeout); -int rbusConfig_UpdateSetMultiTimeout(rbusHandle_t handle, int timeout); -int rbusConfig_UpdatevValueChangePeriod(rbusHandle_t handle, int period); -int rbusConfig_UpdateSubscribeTimeout(rbusHandle_t handle, int timeout); -int rbusConfig_UpdateSubscribeMaxWait(rbusHandle_t handle, int timeout); + char const * rbusError_ToString(rbusError_t e); @@ -2007,6 +1991,45 @@ rbusError_t rbus_registerDynamicTableSyncHandler( rbusError_t rbus_configureTimeoutValues(rbusHandle_t handle, int set_timeout, int get_timeout, int setMulti_timeout, int getWildcard_timeout, int VCPeriod); +/** @fn int rbusHandle_ConfigSetTimeout(rbusHandle_t handle,int timeout) + * @brief function to update SET Timeout value. + * + * @param handle The Bus handle. + * @param timeout The Timeout value for rbus_set operation in milliseconds, + * set to default value if timeout is Zero. + * @return -1 or 0 0 on Success, -1 on failed. + */ +int rbusHandle_ConfigSetTimeout(rbusHandle_t handle,int timeout); + +/** @fn int rbusHandle_ConfigGetTimeout(rbusHandle_t handle,int timeout) + * @brief function to update GET Timeout value. + * + * @param handle The Bus handle. + * @param timeout The Timeout value for rbus_get operation in milliseconds, + * set to default value if timeout is Zero. + * @return -1 or 0 0 on Success, -1 on failed. + */ +int rbusHandle_ConfigGetTimeout(rbusHandle_t handle,int timeout); + +/** @fn int rbusHandle_ConfigWildcardGetTimeout(rbusHandle_t handle,int timeout) + * @brief function to update GET Wildcard query Timeout value. + * + * @param handle The Bus handle. + * @param timeout The Timeout value for rbus_get operation in milliseconds, + * set to default value if timeout is Zero. + * @return -1 or 0 0 on Success, -1 on failed. + */ +int rbusHandle_ConfigWildcardGetTimeout(rbusHandle_t handle, int timeout); + +/** @fn int rbusHandle_ConfigSetMultiTimeout(rbusHandle_t handle,int timeout) + * @brief function to update SetMulti Timeout value. + * + * @param handle The Bus handle. + * @param timeout The Timeout value for rbus_setMulti operation in milliseconds, + * set to default value if timeout is Zero. + * @return -1 or 0 0 on Success, -1 on failed. + */ +int rbusHandle_ConfigSetMultiTimeout(rbusHandle_t handle, int timeout); /** @} */ #ifdef __cplusplus diff --git a/src/rbus/CMakeLists.txt b/src/rbus/CMakeLists.txt index bc9050c0..41b8d614 100644 --- a/src/rbus/CMakeLists.txt +++ b/src/rbus/CMakeLists.txt @@ -40,8 +40,7 @@ add_library( rbus_subscriptions.c rbus_tokenchain.c rbus_asyncsubscribe.c - rbus_intervalsubscription.c - rbus_config.c) + rbus_intervalsubscription.c) target_link_libraries(rbus rbuscore rtMessage -fPIC -pthread) diff --git a/src/rbus/rbus.c b/src/rbus/rbus.c index 5285416f..484c1901 100644 --- a/src/rbus/rbus.c +++ b/src/rbus/rbus.c @@ -34,7 +34,6 @@ #include "rbus_subscriptions.h" #include "rbus_asyncsubscribe.h" #include "rbus_intervalsubscription.h" -#include "rbus_config.h" #include "rbus_log.h" #include "rbus_handle.h" #include "rbus_message.h" @@ -283,10 +282,10 @@ rbusError_t rbus_configureTimeoutValues(rbusHandle_t handle, int set_timeout, int get_timeout, int setMulti_timeout, int getWildcard_timeout, int VCPeriod) { VERIFY_NULL(handle); - rbusConfig_UpdateSetTimeout(handle, set_timeout); - rbusConfig_UpdateGetTimeout(handle, get_timeout); - rbusConfig_UpdateSetMultiTimeout(handle, setMulti_timeout); - rbusConfig_UpdateWildcardGetTimeout(handle, getWildcard_timeout); + rbusHandle_ConfigSetTimeout(handle, set_timeout); + rbusHandle_ConfigGetTimeout(handle, get_timeout); + rbusHandle_ConfigSetMultiTimeout(handle, setMulti_timeout); + rbusHandle_ConfigWildcardGetTimeout(handle, getWildcard_timeout); rbusConfig_UpdatevValueChangePeriod(handle, VCPeriod); return RBUS_ERROR_SUCCESS; } @@ -2890,9 +2889,9 @@ rbusError_t rbus_open(rbusHandle_t* handle, char const* componentName) RBUSLOG_ERROR("(%s): rbus_registerObj error %d", componentName, err); goto exit_error2; } - if (rbusConfig_Init(tmpHandle) != 0) + if (rbusHandle_ConfigInit(tmpHandle) != 0) { - RBUSLOG_ERROR("(%s): rbusConfig_Init failed", componentName); + RBUSLOG_ERROR("(%s): rbusHandle_ConfigInit failed", componentName); goto exit_error2; } tmpHandle->componentName = strdup(componentName); @@ -3118,7 +3117,7 @@ rbusError_t rbus_close(rbusHandle_t handle) componentName = handleInfo->componentName; handleInfo->componentName=NULL; - rbusConfig_Destroy(handle); + rbusHamdle_ConfigDestroy(handle); handleInfo->config = NULL; ERROR_CHECK(pthread_mutex_destroy(&handleInfo->handle_eventSubsMutex)); ERROR_CHECK(pthread_mutex_destroy(&handleInfo->handle_subsMutex)); @@ -3387,7 +3386,7 @@ rbusError_t rbus_get(rbusHandle_t handle, char const* name, rbusValue_t* value) if (NULL == myConn) myConn = handleInfo->m_connection; - err = rbus_invokeRemoteMethod2(myConn, name, METHOD_GETPARAMETERVALUES, request, rbusConfig_ReadGetTimeout(handle), &response); + err = rbus_invokeRemoteMethod2(myConn, name, METHOD_GETPARAMETERVALUES, request, rbusHandle_ConfigGetTimeout(handle), &response); if(err != RBUSCORE_SUCCESS) { @@ -3548,7 +3547,7 @@ rbusError_t rbus_getExt(rbusHandle_t handle, int paramCount, char const** pParam rbusMessage_SetString(request, pParamNames[0]); /* Invoke the method */ err = rbus_invokeRemoteMethod(destinations[i], METHOD_GETPARAMETERVALUES, - request, rbusConfig_ReadWildcardGetTimeout(handle), &response); + request, rbusHandle_ReadWildcardGetTimeout(handle), &response); if(err != RBUSCORE_SUCCESS) { @@ -3711,7 +3710,7 @@ rbusError_t rbus_getExt(rbusHandle_t handle, int paramCount, char const** pParam RBUSLOG_DEBUG("sending batch request with %d params to component %s", batchCount, componentName); free(componentName); - if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_GETPARAMETERVALUES, request, rbusConfig_ReadGetTimeout(handle), &response)) != RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_GETPARAMETERVALUES, request, rbusHandle_ConfigGetTimeout(handle), &response)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("get by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, firstParamName); errorcode = rbusCoreError_to_rbusError(err); @@ -3865,7 +3864,7 @@ rbusError_t rbus_set(rbusHandle_t handle, char const* name,rbusValue_t value, rb if (NULL == myConn) myConn = handleInfo->m_connection; - if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_SETPARAMETERVALUES, setRequest, rbusConfig_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_SETPARAMETERVALUES, setRequest, rbusHandle_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("set by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name); errorcode = rbusCoreError_to_rbusError(err); @@ -3933,7 +3932,7 @@ rbusError_t rbus_setCommit(rbusHandle_t handle, char const* name, rbusSetOptions rtConnection myConn = rbuscore_FindClientPrivateConnection(name); if (NULL == myConn) myConn = handleInfo->m_connection; - if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_COMMIT, setRequest, rbusConfig_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod2(myConn, name, METHOD_COMMIT, setRequest, rbusHandle_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("set commit by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, name); errorcode = rbusCoreError_to_rbusError(err); @@ -4104,7 +4103,7 @@ rbusError_t rbus_setMulti(rbusHandle_t handle, int numProps, rbusProperty_t prop /* Set the Commit value; FIXME: Should we use string? */ rbusMessage_SetString(setRequest, (!opts || opts->commit) ? "TRUE" : "FALSE"); - if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_SETPARAMETERVALUES, setRequest, rbusConfig_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod(firstParamName, METHOD_SETPARAMETERVALUES, setRequest, rbusHandle_ReadSetTimeout(handle), &setResponse)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("set by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, firstParamName); errorcode = rbusCoreError_to_rbusError(err); @@ -4271,7 +4270,7 @@ rbusError_t rbusTable_addRow( because the broker simlpy looks at the top level nodes that are owned by a component route. maybe this breaks if the broker changes*/ METHOD_ADDTBLROW, request, - rbusConfig_ReadSetTimeout(handle), + rbusHandle_ReadSetTimeout(handle), &response)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("Add row by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, tableName); @@ -4337,7 +4336,7 @@ rbusError_t rbusTable_removeRow( rowName, METHOD_DELETETBLROW, request, - rbusConfig_ReadSetTimeout(handle), + rbusHandle_ReadSetTimeout(handle), &response)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("Delete row by %s failed; Received error %d from RBUS Daemon for the object %s", handle->componentName, err, rowName); @@ -4465,7 +4464,7 @@ rbusError_t rbusTable_getRowNames( if (NULL == myConn) myConn = handleInfo->m_connection; - if((err = rbus_invokeRemoteMethod2(myConn, tableName, METHOD_GETPARAMETERNAMES, request, rbusConfig_ReadGetTimeout(handle), &response)) == RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod2(myConn, tableName, METHOD_GETPARAMETERNAMES, request, rbusHandle_ConfigGetTimeout(handle), &response)) == RBUSCORE_SUCCESS) { rbusLegacyReturn_t legacyRetCode = RBUS_LEGACY_ERR_FAILURE; int ret = -1; @@ -4605,7 +4604,7 @@ rbusError_t rbusElementInfo_get( rbusMessage_SetInt32(request, depth);/*depth*/ rbusMessage_SetInt32(request, 0);/*not row names*/ - if((err = rbus_invokeRemoteMethod(destinations[d], METHOD_GETPARAMETERNAMES, request, rbusConfig_ReadGetTimeout(handle), &response)) != RBUSCORE_SUCCESS) + if((err = rbus_invokeRemoteMethod(destinations[d], METHOD_GETPARAMETERNAMES, request, rbusHandle_ConfigGetTimeout(handle), &response)) != RBUSCORE_SUCCESS) { RBUSLOG_ERROR("invokeRemoteMethod %s destination=%s object=%s failed: err=%d", METHOD_GETPARAMETERNAMES, destinations[d], elemName, err); errorcode = rbusCoreError_to_rbusError(err); @@ -4836,7 +4835,7 @@ static rbusError_t rbusEvent_SubscribeWithRetries( if(timeout == -1) { - destNotFoundTimeout = rbusConfig_ReadSubscribeTimeout(handleInfo); + destNotFoundTimeout = RBUS_SUBSCRIBE_TIMEOUT; } else { @@ -5897,7 +5896,7 @@ rbusError_t rbusMethod_Invoke( if (handleInfo->m_handleType != RBUS_HWDL_TYPE_REGULAR) return RBUS_ERROR_INVALID_HANDLE; - return rbusMethod_InvokeInternal(handle, methodName, inParams, outParams, rbusConfig_ReadSetTimeout(handle)); + return rbusMethod_InvokeInternal(handle, methodName, inParams, outParams, rbusHandle_ReadSetTimeout(handle)); } typedef struct _rbusMethodInvokeAsyncData_t @@ -5960,7 +5959,7 @@ rbusError_t rbusMethod_InvokeAsync( data->methodName = strdup(methodName); data->inParams = inParams; data->callback = callback; - data->timeout = timeout > 0 ? (timeout * 1000) : rbusConfig_ReadSetTimeout(handle); /* convert seconds to milliseconds */ + data->timeout = timeout > 0 ? (timeout * 1000) : rbusHandle_ReadSetTimeout(handle); /* convert seconds to milliseconds */ if((err = pthread_create(&pid, NULL, rbusMethod_InvokeAsyncThreadFunc, data)) != 0) { diff --git a/src/rbus/rbus_asyncsubscribe.c b/src/rbus/rbus_asyncsubscribe.c index ba9cd905..acfd31d8 100644 --- a/src/rbus/rbus_asyncsubscribe.c +++ b/src/rbus/rbus_asyncsubscribe.c @@ -18,7 +18,6 @@ */ #define _GNU_SOURCE 1 #include "rbus_asyncsubscribe.h" -#include "rbus_config.h" #include "rbus_log.h" #include #include @@ -40,6 +39,8 @@ #define LOCK() ERROR_CHECK(pthread_mutex_lock(&gRetrier->mutexQueue)) #define UNLOCK() ERROR_CHECK(pthread_mutex_unlock(&gRetrier->mutexQueue)) +#define RBUS_SUBSCRIBE_MAXWAIT 60000 /*subscribe retry max wait between retries in miliseconds*/ + /*defined in rbus.c*/ void _subscribe_async_callback_handler(rbusHandle_t handle, rbusEventSubscription_t* subscription, rbusError_t error, uint32_t subscriptionId); int _event_callback_handler(char const* objectName, char const* eventName, rbusMessage message, void* userData); @@ -102,7 +103,7 @@ static int rbusAsyncSubscribeRetrier_CompareSubscription(const void *pitem, cons return 1; } -static int rbusAsyncSubscribeRetrier_DetermineNextSendTime(rbusHandle_t handle, rtTime_t* nextSendTime) +static int rbusAsyncSubscribeRetrier_DetermineNextSendTime(rtTime_t* nextSendTime) { rtTime_t now; rtListItem li; @@ -110,7 +111,7 @@ static int rbusAsyncSubscribeRetrier_DetermineNextSendTime(rbusHandle_t handle, //find the earliest nextRetryTime using nextSendTime to compare and store rtTime_Now(&now); - rtTime_Later(&now, rbusConfig_ReadSubscribeMaxWait(handle) + 1000, nextSendTime); + rtTime_Later(&now, RBUS_SUBSCRIBE_MAXWAIT + 1000, nextSendTime); RBUSLOG_DEBUG("now=%s", rtTime_ToString(&now, tbuff)); @@ -190,7 +191,7 @@ static void rbusAsyncSubscribeRetrier_SendSubscriptionRequests() elapsed = rtTime_Elapsed(&item->startTime, &now); if(coreerr == RBUSCORE_ERROR_ENTRY_NOT_FOUND && /*the only error that means provider not found yet*/ - elapsed < rbusConfig_ReadSubscribeTimeout(item->subscription->handle)) /*if we haven't timeout out yet*/ + elapsed < RBUS_SUBSCRIBE_TIMEOUT) /*if we haven't timeout out yet*/ { if(item->nextWaitTime == 0) item->nextWaitTime = 1000; //miliseconds @@ -198,11 +199,11 @@ static void rbusAsyncSubscribeRetrier_SendSubscriptionRequests() item->nextWaitTime *= 2;//just double the time //apply a limit to our doubling - if(item->nextWaitTime > rbusConfig_ReadSubscribeMaxWait(item->subscription->handle)) - item->nextWaitTime = rbusConfig_ReadSubscribeMaxWait(item->subscription->handle); + if(item->nextWaitTime > RBUS_SUBSCRIBE_MAXWAIT) + item->nextWaitTime = RBUS_SUBSCRIBE_MAXWAIT; //update nextRetryTime to nextWaitTime miliseconds from now, without exceeding subscribeTimeout - if(elapsed + item->nextWaitTime < rbusConfig_ReadSubscribeTimeout(item->subscription->handle)) + if(elapsed + item->nextWaitTime < RBUS_SUBSCRIBE_TIMEOUT) { rtTime_Later(&now, item->nextWaitTime, &item->nextRetryTime); } @@ -210,13 +211,13 @@ static void rbusAsyncSubscribeRetrier_SendSubscriptionRequests() { //its possible to have the odd situation, based on how subscribeTimeout/subscribeMaxWait are configured, //where this final retry happens very close to the previous retry (e.g. ... wait 60, sub, wait 60, sub, wait 1, sub) - rtTime_Later(&item->startTime, rbusConfig_ReadSubscribeTimeout(item->subscription->handle), &item->nextRetryTime); + rtTime_Later(&item->startTime, RBUS_SUBSCRIBE_TIMEOUT, &item->nextRetryTime); } RBUSLOG_INFO("%s no provider. retry in %d ms with %d left", item->subscription->eventName, rtTime_Elapsed(&now, &item->nextRetryTime), - rbusConfig_ReadSubscribeTimeout(item->subscription->handle) - elapsed ); + RBUS_SUBSCRIBE_TIMEOUT- elapsed ); } else { @@ -273,13 +274,13 @@ static void rbusAsyncSubscribeRetrier_SendSubscriptionRequests() static void* AsyncSubscribeRetrier_threadFunc(void* data) { - rbusHandle_t handle = (rbusHandle_t)data; + (void)data; LOCK(); while(gRetrier->isRunning) { rtTime_t nextSendTime; - while(rbusAsyncSubscribeRetrier_DetermineNextSendTime(handle, &nextSendTime)) + while(rbusAsyncSubscribeRetrier_DetermineNextSendTime(&nextSendTime)) { UNLOCK(); rbusAsyncSubscribeRetrier_SendSubscriptionRequests(); @@ -311,7 +312,7 @@ static void* AsyncSubscribeRetrier_threadFunc(void* data) return NULL; } -static void rbusAsyncSubscribeRetrier_Create(rbusHandle_t handle) +static void rbusAsyncSubscribeRetrier_Create() { pthread_mutexattr_t mattrib; pthread_condattr_t cattrib; @@ -368,7 +369,7 @@ void rbusAsyncSubscribe_AddSubscription(rbusEventSubscription_t* subscription, r if(!gRetrier) { - rbusAsyncSubscribeRetrier_Create((rbusHandle_t)subscription->handle); + rbusAsyncSubscribeRetrier_Create(); } AsyncSubscription_t* item = rt_malloc(sizeof(struct AsyncSubscription_t)); diff --git a/src/rbus/rbus_config.c b/src/rbus/rbus_config.c deleted file mode 100644 index 7f652621..00000000 --- a/src/rbus/rbus_config.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * If not stated otherwise in this file or this component's Licenses.txt file - * the following copyright and licenses apply: - * - * Copyright 2016 RDK Management - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ -#include "rbus_config.h" -#include "rbus.h" -#include "rbus_log.h" -#include -#include -#include -#include -#include "rbus_handle.h" -/* These RBUS_* defines are the list of config settings with their default values - * Each can be overridden using an environment variable of the same name - */ -#define RBUS_TMP_DIRECTORY "/tmp" /*temp directory where persistent data can be stored*/ -#define RBUS_SUBSCRIBE_TIMEOUT 600000 /*subscribe retry timeout in miliseconds*/ -#define RBUS_SUBSCRIBE_MAXWAIT 60000 /*subscribe retry max wait between retries in miliseconds*/ -#define RBUS_VALUECHANGE_PERIOD 2000 /*polling period for valuechange detector*/ -#define RBUS_GET_DEFAULT_TIMEOUT 15000 /* default timeout in miliseconds for GET API */ -#define RBUS_GET_WILDCARD_DEFAULT_TIMEOUT 120000 /* default timeout in miliseconds for Wildcard GET API */ -#define RBUS_SET_DEFAULT_TIMEOUT 15000 /* default timeout in miliseconds for SET API */ - -#define initStr(P,N) \ -{ \ - char* V = getenv(#N); \ - P=strdup((V && strlen(V)) ? V : N); \ - RBUSLOG_DEBUG(#N"=%s",P); \ -} - -#define initInt(P,N) \ -{ \ - char* V = getenv(#N); \ - P=((V && strlen(V)) ? atoi(V) : N); \ - RBUSLOG_DEBUG(#N"=%d",P); \ -} -#define BUF_LEN 128 -#define VERIFY_NULL(T) if(NULL == T){ RBUSLOG_WARN(#T" is NULL"); return -1; } -extern char *__progname; -int rbusConfig_Init(rbusHandle_t handle) -{ - rbusConfig_t *config = NULL; - VERIFY_NULL(handle) - RBUSLOG_DEBUG("%s", __FUNCTION__); - config = rt_malloc(sizeof(struct _rbusConfig_t)); - if (config == NULL) - { - RBUSLOG_WARN("config is NULL"); - return -1; - } - initStr(config->tmpDir, RBUS_TMP_DIRECTORY); - initInt(config->subscribeTimeout, RBUS_SUBSCRIBE_TIMEOUT); - initInt(config->subscribeMaxWait, RBUS_SUBSCRIBE_MAXWAIT); - initInt(config->valueChangePeriod, RBUS_VALUECHANGE_PERIOD); - initInt(config->getTimeout, RBUS_GET_DEFAULT_TIMEOUT); - initInt(config->setTimeout, RBUS_SET_DEFAULT_TIMEOUT); - initInt(config->getWildcardTimeout, RBUS_GET_WILDCARD_DEFAULT_TIMEOUT); - handle->config = config; - return 0; -} - -int rbusConfig_Destroy(rbusHandle_t handle) -{ - VERIFY_NULL(handle) - rbusConfig_t *config = (rbusConfig_t*)handle->config; - if(!config) - return -1; - RBUSLOG_DEBUG("%s", __FUNCTION__); - - free(config->tmpDir); - free(config); - return 0; -} - -rbusConfig_t* rbusConfig_Get(rbusHandle_t handle) -{ - if (handle == NULL) - return NULL; - return handle->config; -} - -int rbusConfig_UpdateGetTimeout(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - if (timeout > 0) - handle->config->getTimeout = timeout; - return handle->config->getTimeout; -} - -/* GET*/ -int rbusConfig_ReadGetTimeout(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - int timeout = 0; - FILE *fp = NULL; - char buf[25] = {0}; - char fileName[BUF_LEN] = {'\0'}; - snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_set", handle->config->tmpDir, __progname); - fileName[BUF_LEN-1] = '\0'; - if (access(fileName, F_OK) == 0) - { - fp = fopen(fileName, "r"); - if(fp != NULL) { - if (fread(buf, 1, sizeof(buf), fp) > 0) - timeout = atoi(buf); - fclose(fp); - } - if (timeout > 0) - return timeout * 1000; - } - return handle->config->getTimeout; -} - -/* Get Wildcard */ -int rbusConfig_UpdateWildcardGetTimeout(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (timeout > 0) - handle->config->getWildcardTimeout = timeout; - return handle->config->getWildcardTimeout; -} - -int rbusConfig_ReadWildcardGetTimeout(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_HANDLE(handle); - VERIFY_NULL(handle->config); - int timeout = 0; - FILE *fp = NULL; - char buf[25] = {0}; - char fileName[BUF_LEN] = {'\0'}; - snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_get_wildcard_query", handle->config->tmpDir, __progname); - fileName[BUF_LEN-1] = '\0'; - if (access(fileName, F_OK) == 0) - { - fp = fopen(fileName, "r"); - if(fp != NULL) { - if (fread(buf, 1, sizeof(buf), fp) > 0) - timeout = atoi(buf); - fclose(fp); - } - if (timeout > 0) - return timeout * 1000; - } - return handle->config->getWildcardTimeout; -} - -/*SET*/ -int rbusConfig_UpdateSetTimeout(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (timeout > 0) - handle->config->setTimeout = timeout; - return handle->config->setTimeout; -} - -int rbusConfig_ReadSetTimeout(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - int timeout = 0; - FILE *fp = NULL; - char buf[25] = {0}; - char fileName[BUF_LEN] = {'\0'}; - snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_set", handle->config->tmpDir, __progname); - fileName[BUF_LEN-1] = '\0'; - if (access(fileName, F_OK) == 0) - { - fp = fopen(fileName, "r"); - if(fp != NULL) { - if (fread(buf, 1, sizeof(buf), fp) > 0) - timeout = atoi(buf); - fclose(fp); - } - if (timeout > 0) - return timeout * 1000; - } - return handle->config->setTimeout; -} - -/* SET Multi */ -int rbusConfig_UpdateSetMultiTimeout(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (timeout > 0) - handle->config->setTimeout = timeout; - return handle->config->setTimeout; -} - -int rbusConfig_ReadSetMultiTimeout(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - int timeout = 0; - FILE *fp = NULL; - char buf[25] = {0}; - char fileName[BUF_LEN] = {'\0'}; - snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_setMulti", handle->config->tmpDir, __progname); - fileName[BUF_LEN-1] = '\0'; - if (access(fileName, F_OK) == 0) - { - fp = fopen(fileName, "r"); - if(fp != NULL) { - if (fread(buf, 1, sizeof(buf), fp) > 0) - timeout = atoi(buf); - fclose(fp); - } - if (timeout > 0) - return timeout * 1000; - } - return handle->config->setMultiTimeout; -} - -/* valueChangePeriod */ -int rbusConfig_UpdatevValueChangePeriod(rbusHandle_t handle, int period) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (period > 0) - handle->config->valueChangePeriod = period; - return handle->config->valueChangePeriod; -} - -int rbusConfig_ReadValueChangePeriod(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - return handle->config->valueChangePeriod; -} - -/* SubscribeTimeout */ -int rbusConfig_UpdateSubscribeTimeout(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (timeout > 0) - handle->config->subscribeTimeout = timeout; - return handle->config->subscribeTimeout; -} - -int rbusConfig_ReadSubscribeTimeout(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - return handle->config->subscribeTimeout; -} - -/* SubscribeMaxWait */ -int rbusConfig_UpdateSubscribeMaxWait(rbusHandle_t handle, int timeout) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - if (timeout > 0) - handle->config->subscribeMaxWait = timeout; - return handle->config->subscribeMaxWait; -} - -int rbusConfig_ReadSubscribeMaxWait(rbusHandle_t handle) -{ - VERIFY_NULL(handle); - VERIFY_NULL(handle->config); - return handle->config->subscribeMaxWait; -} diff --git a/src/rbus/rbus_config.h b/src/rbus/rbus_config.h deleted file mode 100644 index 2d5ade0a..00000000 --- a/src/rbus/rbus_config.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * If not stated otherwise in this file or this component's Licenses.txt file - * the following copyright and licenses apply: - * - * Copyright 2016 RDK Management - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -#ifndef RBUS_CONFIG_H -#define RBUS_CONFIG_H - -#include "rbus.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _rbusConfig_t -{ - char* tmpDir; /* temp directory where rbus can persist data*/ - int subscribeTimeout; /* max time to attempt subscribe retries in milisecond*/ - int subscribeMaxWait; /* max time to wait between subscribe retries in miliseconds*/ - int valueChangePeriod; /* polling period for valuechange detector in miliseconds*/ - int getTimeout; /* default timeout in miliseconds for GET API*/ - int setTimeout; /* default timeout in miliseconds for SET API*/ - int getWildcardTimeout; /* default timeout in miliseconds for Wildcard Query GET API*/ - int setMultiTimeout; /* default timeout in miliseconds for SET Multi API*/ -} rbusConfig_t; - -rbusConfig_t* rbusConfig_Get(rbusHandle_t handle); -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/rbus/rbus_handle.c b/src/rbus/rbus_handle.c index 5758742a..99ff8aa7 100644 --- a/src/rbus/rbus_handle.c +++ b/src/rbus/rbus_handle.c @@ -23,6 +23,26 @@ static rtVector gHandleList = NULL; #define VERIFY_NULL(T,R) if(NULL == T){ RBUSLOG_ERROR(#T" is NULL"); R; } +#define BUF_LEN 128 +#define RBUS_TMP_DIRECTORY "/tmp" /*temp directory where persistent data can be stored*/ +#define RBUS_GET_DEFAULT_TIMEOUT 15000 /* default timeout in miliseconds for GET API */ +#define RBUS_GET_WILDCARD_DEFAULT_TIMEOUT 120000 /* default timeout in miliseconds for Wildcard GET API */ +#define RBUS_SET_DEFAULT_TIMEOUT 15000 /* default timeout in miliseconds for SET API */ + +#define initStr(P,N) \ +{ \ + char* V = getenv(#N); \ + P=strdup((V && strlen(V)) ? V : N); \ + RBUSLOG_DEBUG(#N"=%s",P); \ +} + +#define initInt(P,N) \ +{ \ + char* V = getenv(#N); \ + P=((V && strlen(V)) ? atoi(V) : N); \ + RBUSLOG_DEBUG(#N"=%d",P); \ +} +extern char *__progname; bool rbusHandleList_IsValidHandle(struct _rbusHandle* handle) { @@ -147,3 +167,176 @@ struct _rbusHandle* rbusHandleList_GetByName(char const* componentName) } return handle; } + + +int rbusHandle_ConfigInit(rbusHandle_t handle) +{ + rbusHandleConfig_t *config = NULL; + VERIFY_NULL(handle, return -1) + RBUSLOG_DEBUG("%s", __FUNCTION__); + config = rt_malloc(sizeof(struct _rbusHandleConfig_t)); + if (config == NULL) + { + RBUSLOG_WARN("config is NULL"); + return -1; + } + initStr(config->tmpDir, RBUS_TMP_DIRECTORY); + initInt(config->subscribeTimeout, RBUS_SUBSCRIBE_TIMEOUT); + initInt(config->subscribeMaxWait, RBUS_SUBSCRIBE_MAXWAIT); + initInt(config->valueChangePeriod, RBUS_VALUECHANGE_PERIOD); + initInt(config->getTimeout, RBUS_GET_DEFAULT_TIMEOUT); + initInt(config->setTimeout, RBUS_SET_DEFAULT_TIMEOUT); + initInt(config->getWildcardTimeout, RBUS_GET_WILDCARD_DEFAULT_TIMEOUT); + handle->config = config; + return 0; +} + +int rbusHamdle_ConfigDestroy(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return -1) + rbusHandleConfig_t *config = (rbusHandleConfig_t*)handle->config; + if(!config) + return -1; + RBUSLOG_DEBUG("%s", __FUNCTION__); + + free(config->tmpDir); + free(config); + return 0; +} + +rbusHandleConfig_t* rbusConfig_Get(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return NULL) + return handle->config; +} + +int rbusHandle_ConfigGetTimeout(rbusHandle_t handle, int timeout) +{ + VERIFY_NULL(handle, return -1) + if (timeout > 0) + handle->config->getTimeout = timeout; + return 0; +} + +int rbusHandle_ConfigSetTimeout(rbusHandle_t handle, int timeout) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + if (timeout > 0) + handle->config->setTimeout = timeout; + return 0; +} + +int rbusHandle_ConfigWildcardGetTimeout(rbusHandle_t handle, int timeout) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + if (timeout > 0) + handle->config->getWildcardTimeout = timeout; + return 0; +} + +int rbusHandle_ConfigSetMultiTimeout(rbusHandle_t handle, int timeout) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + if (timeout > 0) + handle->config->setTimeout = timeout; + return 0; +} + +int rbusHandle_ReadGetTimeout(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + int timeout = 0; + FILE *fp = NULL; + char buf[25] = {0}; + char fileName[BUF_LEN] = {'\0'}; + snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_set", handle->config->tmpDir, __progname); + fileName[BUF_LEN-1] = '\0'; + if (access(fileName, F_OK) == 0) + { + fp = fopen(fileName, "r"); + if(fp != NULL) { + if (fread(buf, 1, sizeof(buf), fp) > 0) + timeout = atoi(buf); + fclose(fp); + } + if (timeout > 0) + return timeout * 1000; + } + return handle->config->getTimeout; +} + +int rbusHandle_ReadSetTimeout(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + int timeout = 0; + FILE *fp = NULL; + char buf[25] = {0}; + char fileName[BUF_LEN] = {'\0'}; + snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_set", handle->config->tmpDir, __progname); + fileName[BUF_LEN-1] = '\0'; + if (access(fileName, F_OK) == 0) + { + fp = fopen(fileName, "r"); + if(fp != NULL) { + if (fread(buf, 1, sizeof(buf), fp) > 0) + timeout = atoi(buf); + fclose(fp); + } + if (timeout > 0) + return timeout * 1000; + } + return handle->config->setTimeout; +} + +int rbusHandle_ReadWildcardGetTimeout(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + int timeout = 0; + FILE *fp = NULL; + char buf[25] = {0}; + char fileName[BUF_LEN] = {'\0'}; + snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_get_wildcard_query", handle->config->tmpDir, __progname); + fileName[BUF_LEN-1] = '\0'; + if (access(fileName, F_OK) == 0) + { + fp = fopen(fileName, "r"); + if(fp != NULL) { + if (fread(buf, 1, sizeof(buf), fp) > 0) + timeout = atoi(buf); + fclose(fp); + } + if (timeout > 0) + return timeout * 1000; + } + return handle->config->getWildcardTimeout; +} + +int rbusHandle_ReadSetMultiTimeout(rbusHandle_t handle) +{ + VERIFY_NULL(handle, return -1) + VERIFY_NULL(handle->config, return -1) + int timeout = 0; + FILE *fp = NULL; + char buf[25] = {0}; + char fileName[BUF_LEN] = {'\0'}; + snprintf(fileName, BUF_LEN-1, "%s/rbus_%s_timeout_setMulti", handle->config->tmpDir, __progname); + fileName[BUF_LEN-1] = '\0'; + if (access(fileName, F_OK) == 0) + { + fp = fopen(fileName, "r"); + if(fp != NULL) { + if (fread(buf, 1, sizeof(buf), fp) > 0) + timeout = atoi(buf); + fclose(fp); + } + if (timeout > 0) + return timeout * 1000; + } + return handle->config->setMultiTimeout; +} diff --git a/src/rbus/rbus_handle.h b/src/rbus/rbus_handle.h index acee9cbf..f93f83db 100644 --- a/src/rbus/rbus_handle.h +++ b/src/rbus/rbus_handle.h @@ -23,12 +23,12 @@ #include "rbus_subscriptions.h" #include #include -#include "rbus_config.h" #ifdef __cplusplus extern "C" { #endif +#define RBUS_SUBSCRIBE_TIMEOUT 600000 /*subscribe retry timeout in miliseconds*/ /* RBUS_MAX_HANDLES 16 @@ -99,6 +99,17 @@ typedef enum _rbusHandleType RBUS_HWDL_TYPE_UNKNOWN = 0xB0DE } rbusHandleType_t; +typedef struct _rbusHandleConfig_t +{ + char* tmpDir; /* temp directory where rbus can persist data*/ + int subscribeTimeout; /* max time to attempt subscribe retries in milisecond*/ + int subscribeMaxWait; /* max time to wait between subscribe retries in miliseconds*/ + int valueChangePeriod; /* polling period for valuechange detector in miliseconds*/ + int getTimeout; /* default timeout in miliseconds for GET API*/ + int setTimeout; /* default timeout in miliseconds for SET API*/ + int getWildcardTimeout; /* default timeout in miliseconds for Wildcard Query GET API*/ + int setMultiTimeout; /* default timeout in miliseconds for SET Multi API*/ +} rbusHandleConfig_t; struct _rbusHandle { @@ -119,9 +130,10 @@ struct _rbusHandle pthread_mutex_t handle_eventSubsMutex; pthread_mutex_t handle_subsMutex; rtConnection m_connectionParent; - rbusConfig_t* config; + rbusHandleConfig_t* config; }; + bool rbusHandleList_IsValidHandle(struct _rbusHandle* handle); void rbusHandleList_Add(struct _rbusHandle* handle); void rbusHandleList_Remove(struct _rbusHandle* handle); @@ -131,6 +143,13 @@ void rbusHandleList_ClientDisconnect(char const* clientListener); struct _rbusHandle* rbusHandleList_GetByComponentID(int32_t componentId); struct _rbusHandle* rbusHandleList_GetByName(char const* componentName); +rbusHandleConfig_t* rbusConfig_Get(rbusHandle_t handle); +int rbusHandle_ConfigInit(rbusHandle_t handle); +int rbusHamdle_ConfigDestroy(rbusHandle_t handle); +int rbusHandle_ReadWildcardGetTimeout(rbusHandle_t handle); +int rbusHandle_ReadSetTimeout(rbusHandle_t handle); +int rbusHandle_ReadSetMultiTimeout(rbusHandle_t handle); + #ifdef __cplusplus } #endif diff --git a/src/rbus/rbus_intervalsubscription.c b/src/rbus/rbus_intervalsubscription.c index f648d995..aa83fe21 100644 --- a/src/rbus/rbus_intervalsubscription.c +++ b/src/rbus/rbus_intervalsubscription.c @@ -19,7 +19,6 @@ #define _GNU_SOURCE 1 //needed for pthread_mutexattr_settype #include "rbus_intervalsubscription.h" -#include "rbus_config.h" #include "rbus_handle.h" #include #include diff --git a/src/rbus/rbus_valuechange.c b/src/rbus/rbus_valuechange.c index 84ec895e..ef3ec39c 100644 --- a/src/rbus/rbus_valuechange.c +++ b/src/rbus/rbus_valuechange.c @@ -33,7 +33,6 @@ #define _GNU_SOURCE 1 //needed for pthread_mutexattr_settype #include "rbus_valuechange.h" -#include "rbus_config.h" #include "rbus_handle.h" #include #include @@ -58,6 +57,8 @@ #define LOCK() ERROR_CHECK(pthread_mutex_lock(&gVC->mutex)) #define UNLOCK() ERROR_CHECK(pthread_mutex_unlock(&gVC->mutex)) +#define RBUS_VALUECHANGE_PERIOD 2000 /*polling period for valuechange detector*/ + typedef struct ValueChangeDetector_t { int running; @@ -126,7 +127,7 @@ static ValueChangeRecord* vcParams_Find(const elementNode* paramNode) static void* rbusValueChange_pollingThreadFunc(void *userData) { - rbusHandle_t handle = (rbusHandle_t)userData; + (void)(userData); RBUSLOG_DEBUG("%s: start", __FUNCTION__); LOCK(); while(gVC->running) @@ -136,7 +137,7 @@ static void* rbusValueChange_pollingThreadFunc(void *userData) rtTime_t timeout; rtTimespec_t ts; - rtTime_Later(NULL, rbusConfig_ReadValueChangePeriod(handle), &timeout); + rtTime_Later(NULL, RBUS_VALUECHANGE_PERIOD, &timeout); err = pthread_cond_timedwait(&gVC->cond, &gVC->mutex, @@ -200,10 +201,10 @@ static void* rbusValueChange_pollingThreadFunc(void *userData) then we know it was the provider who updated the value we are now detecting. */ if(rec->node->changeComp == NULL || - (rtTime_Elapsed(&rec->node->changeTime, NULL) >= rbusConfig_ReadValueChangePeriod(handle) && + (rtTime_Elapsed(&rec->node->changeTime, NULL) >= RBUS_VALUECHANGE_PERIOD && strcmp(rec->handle->componentName, rec->node->changeComp) == 0)) { - printf("VC detected provider-side value-change oldcomp=%s elapsed=%d period=%d\n", rec->node->changeComp, rtTime_Elapsed(&rec->node->changeTime, NULL), rbusConfig_ReadValueChangePeriod(handle)); + printf("VC detected provider-side value-change oldcomp=%s elapsed=%d period=%d\n", rec->node->changeComp, rtTime_Elapsed(&rec->node->changeTime, NULL), RBUS_VALUECHANGE_PERIOD); setPropertyChangeComponent((elementNode*)rec->node, rec->handle->componentName); } @@ -320,7 +321,7 @@ void rbusValueChange_AddPropertyNode(rbusHandle_t handle, elementNode* propNode) if(!gVC->running) { gVC->running = 1; - pthread_create(&gVC->thread, NULL, rbusValueChange_pollingThreadFunc, handle); + pthread_create(&gVC->thread, NULL, rbusValueChange_pollingThreadFunc, NULL); } UNLOCK();//############ UNLOCK ############ diff --git a/test/rbus/consumer/subscribe.c b/test/rbus/consumer/subscribe.c index 5b56f0dd..1bdd565a 100644 --- a/test/rbus/consumer/subscribe.c +++ b/test/rbus/consumer/subscribe.c @@ -19,7 +19,6 @@ #include #include -#include #include "../common/test_macros.h" #include #include diff --git a/test/rbus/consumer/valueChange.c b/test/rbus/consumer/valueChange.c index e6eb387d..30177a8b 100644 --- a/test/rbus/consumer/valueChange.c +++ b/test/rbus/consumer/valueChange.c @@ -28,7 +28,7 @@ #include #include #include "../common/test_macros.h" -#include "rbus_config.h" +#include "rbus_handle.h" static int gDuration = 67;