SET(SRCS
src/tracker.c
+ src/services.c
+ src/power_lock.c
)
SET(HEADERS
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
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);
+
+/**
* @}
*/
#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__ */
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
#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;
}