Merge "sensord: delete batch latency/attribute when client is terminated unexpectedly...
[platform/core/system/sensord.git] / src / server / external_sensor_worker.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef _EXTERNAL_SENSOR_WORKER_H_
21 #define _EXTERNAL_SENSOR_WORKER_H_
22
23 #include <worker_thread.h>
24 #include <csocket.h>
25 #include <sensor_common.h>
26 #include <string>
27
28 class external_client_manager;
29 class external_sensor;
30
31 class external_sensor_worker {
32 private:
33         typedef bool (external_sensor_worker::*cmd_handler_t)(void *payload);
34
35         int m_client_id;
36         csocket m_socket;
37         worker_thread m_worker;
38         external_sensor *m_sensor;
39         sensor_id_t m_sensor_id;
40         static cmd_handler_t m_cmd_handlers[CMD_EXT_CNT];
41
42         static void init_cmd_handlers(void);
43         static bool working(void *ctx);
44         static bool stopped(void *ctx);
45
46         bool dispatch_command(int cmd, void *payload);
47
48         bool send_cmd_done(long value);
49         bool send_cmd_get_id_done(int client_id);
50         bool send_cmd_connect_done(sensor_id_t sensor_id);
51
52         bool cmd_get_id(void *payload);
53         bool cmd_connect(void *payload);
54         bool cmd_disconnect(void *payload);
55         bool cmd_post(void *payload);
56
57         static external_client_manager& get_client_manager(void);
58
59         void get_info(std::string &info);
60 public:
61         external_sensor_worker(const csocket& socket);
62         ~external_sensor_worker();
63
64         bool start(void);
65 };
66
67 #endif /* _EXTERNAL_SENSOR_WORKER_H_ */