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