~place_context_provider();
bool init();
- bool is_supported(const char* subject, const char* zone);
- int subscribe(const char* subject, ctx::json option, ctx::json* request_result, const char* zone);
- int unsubscribe(const char* subject, ctx::json option, const char* zone);
- int read(const char* subject, ctx::json option, ctx::json* request_result, const char* zone);
- int write(const char* subject, ctx::json data, ctx::json* request_result, const char* zone);
+ bool is_supported(const char* subject);
+ int subscribe(const char* subject, ctx::json option, ctx::json* request_result);
+ int unsubscribe(const char* subject, ctx::json option);
+ int read(const char* subject, ctx::json option, ctx::json* request_result);
+ int write(const char* subject, ctx::json data, ctx::json* request_result);
}; /* class place_context_provider */
#define CREATE_SUB_PROVIDER(subject, subprovider) do { \
ctx::sub_provider_base *sub = new ctx::subprovider(); \
- if (sub->is_supported(NULL)) { \
+ if (sub->is_supported()) { \
subject_map[(subject)] = sub; \
} else { \
_E("%s is not supported", subject); \
return true;
}
-bool ctx::place_context_provider::is_supported(const char* subject, const char* zone)
+bool ctx::place_context_provider::is_supported(const char* subject)
{
subject_map_t::iterator it = subject_map.find(subject);
if (it != subject_map.end())
- return it->second->is_supported(zone);
+ return it->second->is_supported();
return false;
}
-int ctx::place_context_provider::subscribe(const char* subject, ctx::json option, ctx::json* request_result, const char* zone)
+int ctx::place_context_provider::subscribe(const char* subject, ctx::json option, ctx::json* request_result)
{
subject_map_t::iterator it = subject_map.find(subject);
if (it != subject_map.end())
- return it->second->subscribe(option, request_result, zone);
+ return it->second->subscribe(option, request_result);
return ERR_NOT_SUPPORTED;
}
-int ctx::place_context_provider::unsubscribe(const char* subject, ctx::json option, const char* zone)
+int ctx::place_context_provider::unsubscribe(const char* subject, ctx::json option)
{
subject_map_t::iterator it = subject_map.find(subject);
if (it != subject_map.end())
- return it->second->unsubscribe(option, zone);
+ return it->second->unsubscribe(option);
return ERR_NOT_SUPPORTED;
}
-int ctx::place_context_provider::read(const char* subject, ctx::json option, ctx::json* request_result, const char* zone)
+int ctx::place_context_provider::read(const char* subject, ctx::json option, ctx::json* request_result)
{
subject_map_t::iterator it = subject_map.find(subject);
if (it != subject_map.end())
- return it->second->read(option, request_result, zone);
+ return it->second->read(option, request_result);
return ERR_NOT_SUPPORTED;
}
-int ctx::place_context_provider::write(const char* subject, ctx::json data, ctx::json* request_result, const char* zone)
+int ctx::place_context_provider::write(const char* subject, ctx::json data, ctx::json* request_result)
{
subject_map_t::iterator it = subject_map.find(subject);
if (it != subject_map.end())
- return it->second->write(data, request_result, zone);
+ return it->second->write(data, request_result);
return ERR_NOT_SUPPORTED;
}
stop_monitor();
}
-void ctx::myplace_handle::add_zone(const char* zone)
-{
- _D("'%s' subscribes Place-%d", zone, _place_id);
- _zone.insert(zone);
-}
-
-void ctx::myplace_handle::remove_zone(const char* zone)
-{
- _D("'%s' unsubscribes Place-%d", zone, _place_id);
- _zone.erase(zone);
-}
-
-bool ctx::myplace_handle::zone_empty()
-{
- return _zone.empty();
-}
-
bool ctx::myplace_handle::start_monitor(int place_id)
{
_D("Starts to monitor Place-%d", place_id);
data.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id);
data.set(NULL, PLACE_STATUS_DATA_MYPLACE_EVENT, get_state_string(current_state));
- for (string_set_t::iterator it = _zone.begin(); it != _zone.end(); ++it) {
- context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data, it->c_str());
- }
+ context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data);
}
bool ctx::myplace_handle::fence_list_cb(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void* user_data)
~myplace_handle();
bool start_monitor(int place_id);
- void add_zone(const char* zone);
- void remove_zone(const char* zone);
- bool zone_empty();
int get_place_id();
private:
int _place_id;
- string_set_t _zone;
geofence_state_e prev_state;
geofence_manager_h geo_handle;
geo_state_map_t geo_state_map;
handle_map.clear();
}
-int ctx::place_geofence_detector::subscribe(ctx::json option, ctx::json* request_result, const char* zone)
+int ctx::place_geofence_detector::subscribe(ctx::json option, ctx::json* request_result)
{
int pid = -1;
option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid);
handle_map_t::iterator it = handle_map.find(pid);
if (it != handle_map.end()) {
_D("Place ID %d is being monitored already", pid);
- it->second->add_zone(zone);
return ERR_NONE;
}
return ERR_OPERATION_FAILED;
}
- handle->add_zone(zone);
handle_map[pid] = handle;
return ERR_NONE;
}
-int ctx::place_geofence_detector::unsubscribe(ctx::json option, const char* zone)
+int ctx::place_geofence_detector::unsubscribe(ctx::json option)
{
int pid = -1;
option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid);
return ERR_NONE;
}
- it->second->remove_zone(zone);
- if (it->second->zone_empty()) {
- delete it->second;
- handle_map.erase(it);
- }
+ delete it->second;
+ handle_map.erase(it);
return ERR_NONE;
}
-bool ctx::place_geofence_detector::is_supported(const char* zone)
+bool ctx::place_geofence_detector::is_supported()
{
bool supported = false;
place_geofence_detector();
~place_geofence_detector();
- int subscribe(ctx::json option, ctx::json* request_result, const char* zone);
- int unsubscribe(ctx::json option, const char* zone);
- bool is_supported(const char* zone);
+ int subscribe(ctx::json option, ctx::json* request_result);
+ int unsubscribe(ctx::json option);
+ bool is_supported();
}; /* class place_geofence_detector */
#include "sub_provider_base.h"
-int ctx::sub_provider_base::subscribe(ctx::json option, ctx::json* request_result, const char* zone)
+int ctx::sub_provider_base::subscribe(ctx::json option, ctx::json* request_result)
{
return ERR_NOT_SUPPORTED;
}
-int ctx::sub_provider_base::unsubscribe(ctx::json option, const char* zone)
+int ctx::sub_provider_base::unsubscribe(ctx::json option)
{
return ERR_NOT_SUPPORTED;
}
-int ctx::sub_provider_base::read(ctx::json option, ctx::json* request_result, const char* zone)
+int ctx::sub_provider_base::read(ctx::json option, ctx::json* request_result)
{
return ERR_NOT_SUPPORTED;
}
-int ctx::sub_provider_base::write(ctx::json data, ctx::json* request_result, const char* zone)
+int ctx::sub_provider_base::write(ctx::json data, ctx::json* request_result)
{
return ERR_NOT_SUPPORTED;
}
-bool ctx::sub_provider_base::is_supported(const char* zone)
+bool ctx::sub_provider_base::is_supported()
{
return false;
}
sub_provider_base(){}
virtual ~sub_provider_base(){}
- virtual int subscribe(ctx::json option, ctx::json* request_result, const char* zone);
- virtual int unsubscribe(ctx::json option, const char* zone);
- virtual int read(ctx::json option, ctx::json* request_result, const char* zone);
- virtual int write(ctx::json data, ctx::json* request_result, const char* zone);
- virtual bool is_supported(const char* zone);
+ virtual int subscribe(ctx::json option, ctx::json* request_result);
+ virtual int unsubscribe(ctx::json option);
+ virtual int read(ctx::json option, ctx::json* request_result);
+ virtual int write(ctx::json data, ctx::json* request_result);
+ virtual bool is_supported();
};
}