1caad947b05bf08e5b13ae4cec1f7030ab8b66f6
[framework/location/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
26 /*----------------------------------------------------------------------------*/
27
28         class command
29         {
30         private:
31                 maps_service_h m;
32         protected:
33                 int my_req_id;
34         public:
35                 static volatile int command_request_id;
36         public:
37                 static command empty_instance;
38         private:
39                 command()
40                 {
41                 }               /* Please, do not construct an empty object */
42         public:
43                  command(maps_service_h ms);
44                  command(const command &src);
45                  virtual ~command();
46                  command & operator=(const command &src);
47         public:
48                  virtual int run();
49                 void destroy();
50         public:
51                 static command *empty_ptr()
52                 {
53                         return &empty_instance;
54                 }
55         protected:
56                 plugin::interface_s *interface() const;
57                 maps_plugin_h handle() const;
58         public:
59                 plugin::plugin_s *plugin()const;
60         };
61
62 /*----------------------------------------------------------------------------*/
63
64         class command_handler
65         {
66                 plugin::plugin_s *plg;
67         public:
68                 void *user_data;
69                 int user_req_id;
70                 int plg_req_id;
71         public:
72                  command_handler(plugin::plugin_s *plugin, void *user_data,
73                                  int user_req_id);
74                  virtual ~command_handler();
75         private:
76                  command_handler() : plg(NULL), user_data(NULL),
77                         user_req_id(-1), plg_req_id(-1)
78                 {
79                 };
80                 command_handler(const command_handler &src) : plg(NULL),
81                         user_data(NULL), user_req_id(-1), plg_req_id(-1)
82                 {
83                 };
84                 command_handler &operator=(const command_handler &src)
85                 {
86                         return *this;
87                 }
88         public:
89                 plugin::plugin_s *plugin()const
90                 {
91                         return plg;
92                 }
93         public:
94                 static void destroy(void *p);
95         };
96
97 /*----------------------------------------------------------------------------*/
98
99         class pending_request
100         {
101         private:
102                 plugin::plugin_s *plg;
103         public:
104                 pending_request(plugin::plugin_s *plugin);
105                 virtual ~pending_request()
106                 {
107                 };
108         private:
109                 pending_request() : plg(NULL) {
110                 }
111                 pending_request(const pending_request &src)
112                 {
113                 }
114                 pending_request &operator=(const pending_request &src)
115                 {
116                         return *this;
117                 }
118         public:
119                 bool add(const int user_req_id);
120                 void update(int user_req_id, command_handler *handler);
121                 void remove(int user_req_id);
122                 command_handler *look_up(const int user_req_id);
123                 int extract_plg_id(const int user_req_id);
124                 bool contains(const int user_req_id);
125         private:
126                 int *int_dup(const int n);
127         };
128 }
129
130 #endif                          /* __MAPS_SERVICE_SESSION_COMMAND_H__ */