915ada1a9caa4efd8de5ff7e1de0bfda9b762773
[platform/core/api/maps-service.git] / src / session / command.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __MAPS_SERVICE_SESSION_COMMAND_H__
18 #define __MAPS_SERVICE_SESSION_COMMAND_H__
19
20 #include "maps_plugin.h"
21 #include "module.h"
22
23 namespace session
24 {
25 typedef enum _command_type_e {
26         MAPS_DATA_COMMAND,
27         MAPS_VIEW_SET_CENTER_COMMAND,
28         MAPS_VIEW_MOVE_CENTER_COMMAND,
29         MAPS_VIEW_ZOOM_COMMAND,
30         MAPS_VIEW_ROTATE_COMMAND,
31         MAPS_VIEW_ZOOM_ROTATE_COMMAND,
32         MAPS_VIEW_READY_COMMAND,
33         MAPS_UNDEF_COOMAND = -1
34 } command_type_e;
35
36 /*----------------------------------------------------------------------------*/
37
38 class command
39 {
40         private:
41                 maps_service_h m;
42         protected:
43                 int my_req_id;
44                 int error;
45                 bool is_merged;
46         public:
47                 static volatile int command_request_id;
48         public:
49                 static command empty_instance;
50         private:
51                 command()
52                         : m(NULL), my_req_id(-1), error(0), is_merged(false)
53                 {
54                 }               /* Please, do not construct an empty object */
55         public:
56                  command(maps_service_h ms);
57                  command(const command &src);
58                  virtual ~command();
59                  command & operator=(const command &src);
60         public:
61                  virtual int run();
62                 void destroy();
63         public:
64                 static command *empty_ptr()
65                 {
66                         return &empty_instance;
67                 }
68         protected:
69                 plugin::interface_s *interface() const;
70                 maps_plugin_h handle() const;
71         public:
72                 plugin::plugin_s *plugin()const;
73         public:
74                 virtual command_type_e get_type() const;
75                 virtual int get_priority() const;
76                 virtual void merge(const command *c);
77         public:
78                 bool merged() const;
79         protected:
80                 void set_merged();
81 };
82
83 /*----------------------------------------------------------------------------*/
84
85 class command_handler
86 {
87         private:
88                 plugin::plugin_s *plg;
89         public:
90                 void *user_data;
91                 int user_req_id;
92                 int plg_req_id;
93         public:
94                  command_handler(plugin::plugin_s *plugin, void *user_data,
95                                  int user_req_id);
96                  virtual ~command_handler();
97         private:
98                  command_handler() : plg(NULL), user_data(NULL),
99                         user_req_id(-1), plg_req_id(-1)
100                 {
101                 };
102                 command_handler(const command_handler &src) : plg(NULL),
103                         user_data(NULL), user_req_id(-1), plg_req_id(-1)
104                 {
105                 };
106                 command_handler &operator=(const command_handler &src)
107                 {
108                         return *this;
109                 }
110         public:
111                 plugin::plugin_s *plugin()const
112                 {
113                         return plg;
114                 }
115                 void set_supported_place_data(maps_place_h place);
116                 void set_supported_route_data(maps_route_h route);
117                 void set_supported_place_list_data(maps_place_list_h place_list);
118                 static bool set_supported_place_list_data_cb(int index, maps_place_h place, void *user_data);
119         public:
120                 static void destroy(void *p);
121 };
122
123 /*----------------------------------------------------------------------------*/
124
125 class pending_request
126 {
127         private:
128                 plugin::plugin_s *plg;
129         public:
130                 pending_request(plugin::plugin_s *plugin);
131                 virtual ~pending_request()
132                 {
133                 };
134         private:
135                 pending_request() : plg(NULL) {
136                 }
137                 pending_request(const pending_request &src)
138                 {
139                 }
140                 pending_request &operator=(const pending_request &src)
141                 {
142                         return *this;
143                 }
144         public:
145                 bool add(const int user_req_id);
146                 void update(int user_req_id, command_handler *handler);
147                 void remove(int user_req_id);
148                 command_handler *look_up(const int user_req_id);
149                 int extract_plg_id(const int user_req_id);
150                 bool contains(const int user_req_id);
151         private:
152                 int *int_dup(const int n);
153 };
154 }
155
156 #endif                          /* __MAPS_SERVICE_SESSION_COMMAND_H__ */