*/
HS_Client::HS_Client(afb_req_t request, std::string id) : my_id(id)
{
- AFB_DEBUG("called.");
my_event = afb_api_make_event(request->api, id.c_str());
}
*/
HS_Client::~HS_Client()
{
- AFB_DEBUG("called.");
afb_event_unref(my_event);
}
*/
int HS_Client::subscribe(afb_req_t request)
{
- AFB_DEBUG(" called.");
int ret = 0;
- const char *value = afb_req_value(request, _event);
- if(value) {
- AFB_INFO("subscribe event %s", value);
- if(!isSupportEvent(value)) {
- AFB_WARNING("subscibe event isn't existing.");
- ret = AFB_EVENT_BAD_REQUEST;
+ struct json_object *ev_obj, *req_obj = afb_req_json(request);
+ if(json_object_object_get_ex(req_obj, _event, &ev_obj)) {
+ std::unordered_set<std::string> ev_set;
+ if(json_object_get_type(ev_obj) == json_type_string) {
+ ev_set.insert(json_object_get_string(ev_obj));
+ }
+ else if(json_object_get_type(ev_obj) == json_type_array) {
+ int array_len = json_object_array_length(ev_obj);
+ for (int i = 0; i < array_len; ++i) {
+ struct json_object *obj = json_object_array_get_idx(ev_obj, i);
+ ev_set.insert(json_object_get_string(obj));
+ }
}
else {
- event_list.insert(std::string(value));
- if(!subscription) {
- ret = afb_req_subscribe(request, my_event);
- if(ret == 0) {
- subscription = true;
- }
+ AFB_WARNING("subscibe event type error.");
+ return AFB_EVENT_BAD_REQUEST;
+ }
+
+ if(!subscription) {
+ ret = afb_req_subscribe(request, my_event);
+ if(ret == 0) {
+ subscription = true;
+ }
+ }
+ for(auto &it : ev_set) {
+ AFB_INFO("subscribe event %s", it.c_str());
+ if(!isSupportEvent(it.c_str())) {
+ AFB_WARNING("subscibe event(%s) isn't existing.", it.c_str());
}
- if (!strcasecmp("updateShortcut", value)) {
- pushUpdateShortcutEvent();
+ else {
+ event_list.insert(it.c_str());
}
}
}
*/
int HS_Client::unsubscribe(afb_req_t request)
{
- AFB_DEBUG(" called.");
int ret = 0;
const char *value = afb_req_value(request, _event);
if(value) {
*/
int HS_Client::hideWindow(afb_req_t request)
{
- AFB_DEBUG(" called.");
std::string req_appid = std::move(get_application_id(request));
if(req_appid.empty()) {
AFB_WARNING("can't get application identifier");
*/
int HS_Client::showNotification(afb_req_t request)
{
- AFB_DEBUG(" called.");
int ret = 0;
const char *value = afb_req_value(request, _text);
if(value) {
*/
int HS_Client::showInformation(afb_req_t request)
{
- AFB_DEBUG(" called.");
int ret = 0;
const char *value = afb_req_value(request, _info);
if(value) {
*/
int HS_Client::handleRequest(afb_req_t request, const char *verb)
{
- AFB_DEBUG("called.");
if((strcasecmp(verb, "subscribe") && strcasecmp(verb, "unsubscribe")) && !checkEvent(verb))
return 0;
if(!checkEvent(event))
return 0;
- AFB_INFO("called, event=%s.",event);
+ AFB_INFO("called, event=%s.", event);
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 4, _application_id, my_id.c_str(), _type, event);
if(param != nullptr)