Set the minimum value of tracker_type_e
[platform/core/system/libtracker.git] / src / tracker.c
1 /*
2  * libtracker
3  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"),
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 */
17
18 #include "tracker.h"
19 #include "tracker_private.h"
20
21 struct ops *trackers[TRACKER_TYPE_MAX];
22
23 API int tracker_get_ref_counter(tracker_type_e type, int *cnt)
24 {
25         int ref;
26
27         if (type <= TRACKER_TYPE_INVALID || type >= TRACKER_TYPE_MAX || !trackers[type]) {
28                 _E("Try to access not existed tracker %d", type);
29                 return TRACKER_ERROR_INVALID_PARAMETER;
30         }
31
32         ref = trackers[type]->get_ref_counter();
33         if (ref < 0) {
34                 _E("Failed to get power lock reference count(%d)", ref);
35                 return ref;
36         }
37
38         *cnt = ref;
39         return TRACKER_ERROR_NONE;
40 }
41
42 API int tracker_get_tick(tracker_type_e type, int *cnt)
43 {
44         int count;
45
46         if (type <= TRACKER_TYPE_INVALID || type >= TRACKER_TYPE_MAX || !trackers[type]) {
47                 _E("Try to access not existed tracker %d", type);
48                 return TRACKER_ERROR_INVALID_PARAMETER;
49         }
50
51         count = trackers[type]->get_tick();
52         if (count < 0) {
53                 _E("Failed to get power lock total count(%d)", count);
54                 return count;
55         }
56
57         *cnt = count;
58         return TRACKER_ERROR_NONE;
59 }
60
61 API int tracker_start_services(int services)
62 {
63         if (services < 0)
64                 return TRACKER_ERROR_INVALID_PARAMETER;
65
66         if (services & TRACKER_SERVICE_DOWNLOAD)
67                 start_service_download();
68         if (services & TRACKER_SERVICE_MEDIA)
69                 start_service_media();
70         if (services & TRACKER_SERVICE_NETWORK)
71                 start_service_network();
72         if (services & TRACKER_SERVICE_LOCATION)
73                 start_service_location();
74         if (services & TRACKER_SERVICE_SENSOR)
75                 start_service_sensor();
76         if (services & TRACKER_SERVICE_IOT)
77                 start_service_iot();
78
79         return TRACKER_ERROR_NONE;
80 }
81
82 API int tracker_stop_services(int services)
83 {
84         if (services < 0)
85                 return TRACKER_ERROR_INVALID_PARAMETER;
86
87         if (services & TRACKER_SERVICE_DOWNLOAD)
88                 stop_service_download();
89         if (services & TRACKER_SERVICE_MEDIA)
90                 stop_service_media();
91         if (services & TRACKER_SERVICE_NETWORK)
92                 stop_service_network();
93         if (services & TRACKER_SERVICE_LOCATION)
94                 stop_service_location();
95         if (services & TRACKER_SERVICE_SENSOR)
96                 stop_service_sensor();
97         if (services & TRACKER_SERVICE_IOT)
98                 stop_service_iot();
99
100         return TRACKER_ERROR_NONE;
101 }