* limitations under the License.
*/
+#define _GNU_SOURCE
+#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <system_info.h>
#include "tethering_private.h"
-int tethering_check_feature_supported(const char* feature, ...)
+static pthread_mutex_t g_tethering_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static bool is_feature_checked[TETHERING_SUPPORTED_FEATURE_MAX] = {0, };
+static bool feature_supported[TETHERING_SUPPORTED_FEATURE_MAX] = {0, };
+static GSList *tethering_handle_list = NULL;
+
+void _tethering_lock(void)
+{
+ pthread_mutex_lock(&g_tethering_thread_mutex);
+}
+
+void _tethering_unlock(void)
+{
+ pthread_mutex_unlock(&g_tethering_thread_mutex);
+}
+
+bool __check_feature_supported(const char *key, tethering_supported_feature_e feature)
+{
+ TETHERING_LOCK;
+ bool is_supported = false;
+
+ if (!is_feature_checked[feature]) {
+ if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
+ ERR("Get feature is failed");
+ TETHERING_UNLOCK;
+ return false;
+ }
+
+ is_feature_checked[feature] = true;
+ }
+
+ is_supported = feature_supported[feature];
+
+ TETHERING_UNLOCK;
+ return is_supported;
+}
+
+int _tethering_check_feature_supported(const char* feature, ...)
{
va_list list;
const char *key;
- int ret;
- bool value, supported = false;
+ bool value = false;
+ bool supported = false;
va_start(list, feature);
key = feature;
+
while (1) {
- ret = system_info_get_platform_bool(key, &value);
- if (ret < 0) {
- ERR("Get feature is failed\n");
- return TETHERING_ERROR_OPERATION_FAILED;
- }
+ if ((strcmp(key, TETHERING_FEATURE) == 0))
+ value = __check_feature_supported(key, TETHERING_SUPPORTED_FEATURE);
+ if ((strcmp(key, TETHERING_WIFI_FEATURE) == 0))
+ value = __check_feature_supported(key, TETHERING_SUPPORTED_FEATURE_WIFI);
+ if ((strcmp(key, TETHERING_BT_FEATURE) == 0))
+ value = __check_feature_supported(key, TETHERING_SUPPORTED_FEATURE_BT);
+ if ((strcmp(key, TETHERING_USB_FEATURE) == 0))
+ value = __check_feature_supported(key, TETHERING_SUPPORTED_FEATURE_USB);
+
supported |= value;
key = va_arg(list, const char *);
if (!key) break;
}
- if (!supported)
+ if (!supported) {
+ ERR("Not supported feature");
+ set_last_result(TETHERING_ERROR_NOT_SUPPORT_API);
+ va_end(list);
return TETHERING_ERROR_NOT_SUPPORT_API;
+ }
+ va_end(list);
+ set_last_result(TETHERING_ERROR_NONE);
return TETHERING_ERROR_NONE;
}
+
+void _tethering_add_handle(tethering_h handle)
+{
+ TETHERING_LOCK;
+ tethering_handle_list = g_slist_append(tethering_handle_list, handle);
+ TETHERING_UNLOCK;
+}
+
+void _tethering_remove_handle(tethering_h handle)
+{
+ TETHERING_LOCK;
+ tethering_handle_list = g_slist_remove(tethering_handle_list, handle);
+ TETHERING_UNLOCK;
+}
+
+bool _tethering_check_handle(tethering_h handle)
+{
+ TETHERING_LOCK;
+
+ if (g_slist_find(tethering_handle_list, handle) != NULL) {
+ TETHERING_UNLOCK;
+ return true;
+ }
+
+ TETHERING_UNLOCK;
+ return false;
+}
+