1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "empty_module.h"
19 #include "maps_util.h"
21 extern plugin::plugin_s *__extract_plugin(maps_service_h maps);
23 volatile int session::command::command_request_id = 1;
24 session::command session::command::empty_instance; //LCOV_EXCL_LINE
26 session::command::command(maps_service_h ms)
27 : m(ms), my_req_id(0), error(MAPS_ERROR_NONE), is_merged(false)
32 session::command::command(const command &src)
37 session::command::~command()
41 session::command &session::command::operator =(const command &src)
45 my_req_id = src.my_req_id;
47 is_merged = src.is_merged;
52 int session::command::run()
54 return MAPS_ERROR_NONE;
58 void session::command::destroy()
60 if (this != empty_ptr())
64 plugin::interface_s *session::command::interface() const
67 return plugin::get_empty_interface_ptr(); //LCOV_EXCL_LINE
69 plugin::plugin_s *p = __extract_plugin(m);
71 return plugin::get_empty_interface_ptr(); //LCOV_EXCL_LINE
77 maps_plugin_h session::command::handle() const
79 return (maps_plugin_h) plugin();
82 plugin::plugin_s *session::command::plugin() const
84 return __extract_plugin(m);
87 session::command_type_e session::command::get_type() const
89 /* Default command type */
90 return MAPS_DATA_COMMAND;
93 int session::command::get_priority() const
95 /* Default command priority */
99 void session::command::merge(const command *c)
104 bool session::command::merged() const
110 void session::command::set_merged()
115 /*----------------------------------------------------------------------------*/
117 session::command_handler::command_handler(plugin::plugin_s *p, void *ud,
119 : plg(p), user_data(ud), user_req_id(urid), plg_req_id(-1)
123 session::command_handler::~command_handler()
127 void session::command_handler::destroy(void *p)
131 command_handler *c = (command_handler *) p;
135 /*----------------------------------------------------------------------------*/
137 session::pending_request::pending_request(plugin::plugin_s *p) : plg(p)
141 bool session::pending_request::add(const int user_req_id)
143 if (!plg || !plg->pending_request_maps || (user_req_id < 0))
145 plugin::scope_mutex(&plg->pending_request_mutex);
147 MAPS_LOGD("session::pending_request::add: %d", user_req_id);
149 if (contains(user_req_id))
150 return false; /* Attempt to add another instance of the id */
151 g_hash_table_insert(plg->pending_request_maps, int_dup(user_req_id),
156 void session::pending_request::update(int user_req_id,
157 command_handler *handler)
159 if (!plg || !plg->pending_request_maps || (user_req_id < 0) || !handler)
161 plugin::scope_mutex(&plg->pending_request_mutex);
163 MAPS_LOGD("session::pending_request::update: %d, %d", user_req_id,
164 handler->plg_req_id);
166 if (!contains(user_req_id)) { /* Attempt to update not existing id */
168 MAPS_LOGD("\t not updated session::pending_request: %d, %d",
169 user_req_id, handler->plg_req_id);
170 delete handler; /* This handler must be deleted */
175 g_hash_table_insert(plg->pending_request_maps, int_dup(user_req_id),
179 void session::pending_request::remove(int user_req_id)
181 if (!plg || !plg->pending_request_maps || (user_req_id < 0))
183 plugin::scope_mutex(&plg->pending_request_mutex);
185 MAPS_LOGD("session::pending_request::remove: %d", user_req_id);
187 if (!contains(user_req_id))
188 return; /* Attempt to remove not existing id */
189 g_hash_table_remove(plg->pending_request_maps, &user_req_id);
192 session::command_handler *session::pending_request::look_up(const int
195 if (!plg || !plg->pending_request_maps || (user_req_id < 0))
197 plugin::scope_mutex(&plg->pending_request_mutex);
199 MAPS_LOGD("session::pending_request::look_up: %d", user_req_id);
201 if (!contains(user_req_id))
202 return NULL; /* Attempt to query not existing id */
203 return (command_handler*) g_hash_table_lookup(plg->
204 pending_request_maps, &user_req_id);
207 int session::pending_request::extract_plg_id(const int user_req_id)
209 if (!plg || !plg->pending_request_maps || (user_req_id < 0))
211 plugin::scope_mutex(&plg->pending_request_mutex);
213 command_handler* ch = look_up(user_req_id);
216 const int plg_req_id = ch->plg_req_id;
221 bool session::pending_request::contains(const int user_req_id)
223 if (!plg || !plg->pending_request_maps || (user_req_id < 0))
225 plugin::scope_mutex(&plg->pending_request_mutex);
227 return g_hash_table_contains(plg->pending_request_maps, &user_req_id);
231 int *session::pending_request::int_dup(const int n)
233 int *clone = g_new0(int, 1);