tracker: add start/stop tracking apis for internal usages 68/57468/3
authorTaeyoung Kim <ty317.kim@samsung.com>
Wed, 20 Jan 2016 09:31:08 +0000 (18:31 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Wed, 20 Jan 2016 10:27:39 +0000 (19:27 +0900)
- The apis will be used only in the framework layer
  of the Tizen Platform. Now they are used
  to handle power lock reference count. But
  it will be used for more information to handle
  resources of framework.

- The reference count is increased when power is locked
  and the reference count is decreases when power is ulocked.
  There are several reference counts for each service
  because power can be locked several times by the usage
  of other apis.

Change-Id: I38df55bcf0654647d7ecb34389a4db558dee6a9b
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
CMakeLists.txt
include/tracker.h
include/tracker_private.h
src/power_lock.c [new file with mode: 0644]
src/services.c [new file with mode: 0644]
src/tracker.c

index 88e32bb..6053937 100644 (file)
@@ -18,6 +18,8 @@ SET(PKG_MODULES
 
 SET(SRCS
        src/tracker.c
+       src/services.c
+       src/power_lock.c
 )
 
 SET(HEADERS
index 0154a39..87f1d61 100644 (file)
@@ -43,6 +43,15 @@ typedef enum {
        TRACKER_ERROR_NOT_SUPPORTED     = TIZEN_ERROR_NOT_SUPPORTED,     /**< The api is not supported */
 } tracker_error_e;
 
+typedef enum {
+       TRACKER_SERVICE_DOWNLOAD = 1 << 0, /**< download services */
+       TRACKER_SERVICE_MEDIA    = 1 << 1, /**< media operations */
+       TRACKER_SERVICE_NETWORK  = 1 << 2, /**< network services */
+       TRACKER_SERVICE_LOCATION = 1 << 3, /**< location services */
+       TRACKER_SERVICE_SENSOR   = 1 << 4, /**< sensor information */
+       TRACKER_SERVICE_IOT      = 1 << 5, /**< IoT services */
+} tracker_service_e;
+
 /**
  * @brief   Gets the reference count of the Power Lock operation
  * @since_tizen 3.0
@@ -56,6 +65,32 @@ typedef enum {
 int tracker_get_power_lock_ref(int *count);
 
 /**
+ * @brief   Start tracking for information of services
+ * @details The api should be used only in the framework, not in applications
+ * @since_tizen 3.0
+ * @param[in] services The services to use internally
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #TRACKER_ERROR_NONE Successful
+ * @retval  #TRACKER_ERROR_INVALID_PARAMETER The input parameter is invalid
+ * @retval  #TRACKER_ERROR_PERMISSION_DENIED No permission to use the API
+ */
+int tracker_start_services(int services);
+
+/**
+ * @brief   Stop tracking for information of services
+ * @details The api should be used only in the framework, not in applications
+ * @since_tizen 3.0
+ * @param[in] services The services not to use internally
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #TRACKER_ERROR_NONE Successful
+ * @retval  #TRACKER_ERROR_INVALID_PARAMETER The input parameter is invalid
+ * @retval  #TRACKER_ERROR_PERMISSION_DENIED No permission to use the API
+ */
+int tracker_stop_services(int services);
+
+/**
  * @}
  */
 
index 1f11431..a9dd764 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <dlog.h>
 
+#include "tracker.h"
+
 #ifndef API
 #define API __attribute__ ((visibility("default")))
 #endif
 
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
 
+int get_power_lock_ref(void);
+void power_lock_ref(tracker_service_e service);
+void power_lock_unref(tracker_service_e service);
+
+char *service_name_str(tracker_service_e svc, char *buf, size_t len);
+
+void start_service_download(void);
+void stop_service_download(void);
+
+void start_service_media(void);
+void stop_service_media(void);
+
+void start_service_network(void);
+void stop_service_network(void);
+
+void start_service_location(void);
+void stop_service_location(void);
+
+void start_service_sensor(void);
+void stop_service_sensor(void);
+
+void start_service_iot(void);
+void stop_service_iot(void);
+
+
 #endif /* __LIBTRACKER_TRACKER_PRIVATE_H__ */
diff --git a/src/power_lock.c b/src/power_lock.c
new file mode 100644 (file)
index 0000000..e75963f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * libtracker
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "tracker.h"
+#include "tracker_private.h"
+
+#define POWERLOCK_DEFAULT_REF 0
+
+struct powerlock_ref {
+       tracker_service_e service;
+       unsigned int ref;
+} lock_refs[] = {
+       { TRACKER_SERVICE_DOWNLOAD, POWERLOCK_DEFAULT_REF },
+       { TRACKER_SERVICE_MEDIA,    POWERLOCK_DEFAULT_REF },
+       { TRACKER_SERVICE_NETWORK,  POWERLOCK_DEFAULT_REF },
+       { TRACKER_SERVICE_LOCATION, POWERLOCK_DEFAULT_REF },
+       { TRACKER_SERVICE_SENSOR,   POWERLOCK_DEFAULT_REF },
+       { TRACKER_SERVICE_IOT,      POWERLOCK_DEFAULT_REF },
+};
+
+int get_power_lock_ref(void)
+{
+       int sum = 0, i;
+
+       for (i = 0 ; i < ARRAY_SIZE(lock_refs) ; i++)
+               sum += lock_refs[i].ref;
+
+       _I("Total reference count of pid(%d) is (%d)",
+                               getpid(), sum);
+
+       return sum;
+}
+
+void power_lock_ref(tracker_service_e service)
+{
+       int i;
+       char buf[32];
+
+       for (i = 0 ; i < ARRAY_SIZE(lock_refs) ; i++) {
+               if (lock_refs[i].service != service)
+                       continue;
+               lock_refs[i].ref++;
+               _I("[%s] pid(%d) increases power lock ref count to (%d)",
+                               service_name_str(service, buf, sizeof(buf)),
+                               getpid(), lock_refs[i].ref);
+               break;
+       }
+}
+
+void power_lock_unref(tracker_service_e service)
+{
+       int i;
+       char buf[32];
+
+       for (i = 0 ; i < ARRAY_SIZE(lock_refs) ; i++) {
+               if (lock_refs[i].service != service)
+                       continue;
+               if (lock_refs[i].ref > 0)
+                       lock_refs[i].ref--;
+               _I("[%s] pid(%d) decreases power lock ref count to (%d)",
+                               service_name_str(service, buf, sizeof(buf)),
+                               getpid(), lock_refs[i].ref);
+               break;
+       }
+}
diff --git a/src/services.c b/src/services.c
new file mode 100644 (file)
index 0000000..08b3ead
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * libtracker
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "tracker.h"
+#include "tracker_private.h"
+
+char *service_name_str(tracker_service_e svc, char *buf, size_t len)
+{
+       char *str;
+
+       if (!buf)
+               return NULL;
+
+       switch (svc) {
+       case TRACKER_SERVICE_DOWNLOAD:
+               str = "DOWNLOAD";
+               break;
+       case TRACKER_SERVICE_MEDIA:
+               str = "MEDIA";
+               break;
+       case TRACKER_SERVICE_NETWORK:
+               str = "NETWORK";
+               break;
+       case TRACKER_SERVICE_LOCATION:
+               str = "LOCATION";
+               break;
+       case TRACKER_SERVICE_SENSOR:
+               str = "SENSOR";
+               break;
+       case TRACKER_SERVICE_IOT:
+               str = "IoT";
+               break;
+       default:
+               str = "unknown";
+               break;
+       }
+
+       snprintf(buf, len, "%s", str);
+       return str;
+}
+
+void power_lock_ref_download(void)
+{
+       power_lock_ref(TRACKER_SERVICE_DOWNLOAD);
+}
+
+void power_lock_unref_download(void)
+{
+       power_lock_unref(TRACKER_SERVICE_DOWNLOAD);
+}
+
+void power_lock_ref_media(void)
+{
+       power_lock_ref(TRACKER_SERVICE_MEDIA);
+}
+
+void power_lock_unref_media(void)
+{
+       power_lock_unref(TRACKER_SERVICE_MEDIA);
+}
+
+void power_lock_ref_network(void)
+{
+       power_lock_ref(TRACKER_SERVICE_NETWORK);
+}
+
+void power_lock_unref_network(void)
+{
+       power_lock_unref(TRACKER_SERVICE_NETWORK);
+}
+
+void power_lock_ref_location(void)
+{
+       power_lock_ref(TRACKER_SERVICE_LOCATION);
+}
+
+void power_lock_unref_location(void)
+{
+       power_lock_unref(TRACKER_SERVICE_LOCATION);
+}
+
+void power_lock_ref_sensor(void)
+{
+       power_lock_ref(TRACKER_SERVICE_SENSOR);
+}
+
+void power_lock_unref_sensor(void)
+{
+       power_lock_unref(TRACKER_SERVICE_SENSOR);
+}
+
+void power_lock_ref_iot(void)
+{
+       power_lock_ref(TRACKER_SERVICE_IOT);
+}
+
+void power_lock_unref_iot(void)
+{
+       power_lock_unref(TRACKER_SERVICE_IOT);
+}
index 19cea74..574a2f1 100644 (file)
 #include "tracker.h"
 #include "tracker_private.h"
 
-static int power_lock_ref = 0;
-
 API int tracker_get_power_lock_ref(int *cnt)
 {
-       _I("Power Lock reference count: (%d)", power_lock_ref);
-       *cnt = power_lock_ref;
+       int ref;
+
+       ref = get_power_lock_ref();
+       if (ref < 0) {
+               _E("Failed to get power lock reference count(%d)", ref);
+               return ref;
+       }
+
+       *cnt = ref;
+       return TRACKER_ERROR_NONE;
+}
+
+API int tracker_start_services(int services)
+{
+       if (services < 0)
+               return TRACKER_ERROR_INVALID_PARAMETER;
+
+       if (services & TRACKER_SERVICE_DOWNLOAD)
+               start_service_download();
+       if (services & TRACKER_SERVICE_MEDIA)
+               start_service_media();
+       if (services & TRACKER_SERVICE_NETWORK)
+               start_service_network();
+       if (services & TRACKER_SERVICE_LOCATION)
+               start_service_location();
+       if (services & TRACKER_SERVICE_SENSOR)
+               start_service_sensor();
+       if (services & TRACKER_SERVICE_IOT)
+               start_service_iot();
+
+       return TRACKER_ERROR_NONE;
+}
+
+API int tracker_stop_services(int services)
+{
+       if (services < 0)
+               return TRACKER_ERROR_INVALID_PARAMETER;
+
+       if (services & TRACKER_SERVICE_DOWNLOAD)
+               stop_service_download();
+       if (services & TRACKER_SERVICE_MEDIA)
+               stop_service_media();
+       if (services & TRACKER_SERVICE_NETWORK)
+               stop_service_network();
+       if (services & TRACKER_SERVICE_LOCATION)
+               stop_service_location();
+       if (services & TRACKER_SERVICE_SENSOR)
+               stop_service_sensor();
+       if (services & TRACKER_SERVICE_IOT)
+               stop_service_iot();
+
        return TRACKER_ERROR_NONE;
 }