*/
#include <unistd.h>
+#include <cstring>
#include "hs-appinfo.h"
-#include "hmi-debug.h"
+#include "hs-helper.h"
#include "hs-clientmanager.h"
#define RETRY_CNT 10
const char _keyApplistChanged[] = "application-list-changed";
HS_AppInfo* HS_AppInfo::me = nullptr;
+const std::unordered_map<std::string, HS_AppInfo::func_handler> HS_AppInfo::concerned_event_list {
+ {"afm-main/application-list-changed", &HS_AppInfo::updateAppDetailList}
+};
+
+
+/**
+ * event hook function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - event : event name
+ * - object : event json object
+ *
+ * #### Return
+ * 0 : continue transfer
+ * 1 : blocked
+ *
+ */
+static int eventHandler(afb_api_t api, const char *event, struct json_object *object)
+{
+ return HS_AppInfo::instance()->onEvent(api, event, object);
+}
/**
* get application property function
struct json_object *j_obj;
struct json_object *j_detail = json_tokener_parse(this->detail.c_str());
if(json_object_object_get_ex(j_detail, key.c_str(), &j_obj) == 0) {
- HMI_ERROR("homescreen-service","can't find key=%s.", key.c_str());
+ AFB_WARNING("can't find key=%s.", key.c_str());
return std::string();
}
return std::string(json_object_get_string(j_obj));
{
afmmain = new HS_AfmMainProxy();
if(afmmain == nullptr) {
- HMI_ERROR("homescreen-service","Fatal Error:new HS_AfmMainProxy failed");
+ AFB_ERROR("new HS_AfmMainProxy failed");
return -1;
}
++retry;
if(retry == RETRY_CNT) {
- HMI_ERROR("homescreen-service","get runnables list failed");
+ AFB_ERROR("get runnables list failed");
json_object_put(j_runnable);
return -1;
}
- HMI_NOTICE("homescreen-service","retry to get runnables list %d", retry);
+ AFB_DEBUG("retry to get runnables list %d", retry);
usleep(100000); // 100ms
} while(1);
+ for(auto &ref : concerned_event_list) {
+ setEventHook(ref.first.c_str(), eventHandler);
+ }
+
return 0;
}
* - object : event json object
*
* #### Return
- * None
- *
+ * 0 : continue transfer
+ * 1 : blocked
*/
-void HS_AppInfo::onEvent(afb_api_t api, const char *event, struct json_object *object)
+int HS_AppInfo::onEvent(afb_api_t api, const char *event, struct json_object *object)
{
+ int ret = 0;
auto ip = concerned_event_list.find(std::string(event));
if(ip != concerned_event_list.end()) {
- HMI_NOTICE("homescreen-service","[%s] event received.", event);
- (this->*(ip->second))(api, object);
+ ret = (this->*(ip->second))(api, object);
}
+ return ret;
}
/**
*/
void HS_AppInfo::createAppDetailList(struct json_object *object)
{
- HMI_NOTICE("homescreen-service","applist:%s", json_object_to_json_string(object));
+ AFB_DEBUG("applist:%s", json_object_to_json_string(object));
if(json_object_get_type(object) == json_type_array) {
int array_len = json_object_array_length(object);
}
}
else {
- HMI_ERROR("homescreen-service","Apps information input error.");
+ AFB_ERROR("Apps information input error.");
}
}
* - object : the detail of all applications
*
* #### Return
- * None
+ * 0 : continue transfer
+ * 1 : blocked
*
*/
-void HS_AppInfo::updateAppDetailList(afb_api_t api, struct json_object *object)
+int HS_AppInfo::updateAppDetailList(afb_api_t api, struct json_object *object)
{
- HMI_NOTICE("homescreen-service","update:%s", json_object_to_json_string(object));
+ AFB_DEBUG("update:%s", json_object_to_json_string(object));
if(json_object_get_type(object) != json_type_object) {
- HMI_ERROR("homescreen-service","input detail object error.");
- return;
+ AFB_ERROR("input detail object error.");
+ return 1;
}
struct json_object *obj_oper, *obj_data;
if(json_object_object_get_ex(object, _keyOperation, &obj_oper) == 0
|| json_object_object_get_ex(object, _keyData, &obj_data) == 0) {
- HMI_ERROR("homescreen-service","can't find key=%s, %s.", _keyOperation, _keyData);
- return;
+ AFB_ERROR("can't find key=%s, %s.", _keyOperation, _keyData);
+ return 1;
}
std::string id = json_object_get_string(obj_data);
std::string appid = id2appid(id);
if(isPeripheryApp(appid.c_str())) {
- HMI_NOTICE("homescreen-service", "install/uninstall application is periphery.");
- return;
+ AFB_INFO( "install/uninstall application is periphery.");
+ return 1;
}
std::string oper = json_object_get_string(obj_oper);
if(!ret) {
struct json_object *j_found = retrieveRunnables(j_runnable, id);
if(j_found == nullptr) {
- HMI_NOTICE("homescreen-service", "installed application isn't runnables.");
+ AFB_INFO( "installed application isn't runnables.");
json_object_put(j_runnable);
- return;
+ return 1;
}
- addAppDetail(j_found);
+ addAppDetail(json_object_get(j_found));
pushAppListChangedEvent(_keyInstall, j_found);
}
else {
- HMI_ERROR("homescreen-service","get runnalbes failed.");
+ AFB_ERROR("get runnalbes failed.");
}
json_object_put(j_runnable);
}
else if(oper == _keyUninstall) {
std::string appid_checked = checkAppId(appid);
if(appid_checked.empty()) {
- HMI_NOTICE("homescreen-service","uninstalled application isn't in runnables list, appid=%s.", appid.c_str());
- return;
+ AFB_INFO("uninstalled application isn't in runnables list, appid=%s.", appid.c_str());
+ return 1;
}
- pushAppListChangedEvent(_keyUninstall, obj_data);
+ pushAppListChangedEvent(_keyUninstall, json_object_get(obj_data));
removeAppDetail(appid);
}
else {
- HMI_ERROR("homescreen-service","operation error.");
+ AFB_ERROR("operation error.");
}
+ return 1;
}
/**
struct json_object *name, *id;
if(json_object_object_get_ex(object, _keyName, &name) == 0
|| json_object_object_get_ex(object, _keyId, &id) == 0) {
- HMI_ERROR("homescreen-service","can't find key=%s, %s.", _keyName, _keyId);
+ AFB_ERROR("can't find key=%s, %s.", _keyName, _keyId);
return std::string();
}
std::string appid = id2appid(json_object_get_string(id));
AppDetail info;
std::string appid = parseAppDetail(object, info);
if(appid.empty()) {
- HMI_ERROR("homescreen-service","application id error");
+ AFB_ERROR("application id error");
return;
}
app_detail_list.erase(it);
}
else {
- HMI_WARNING("homescreen-service","erase application(%s) wasn't in applist.", appid.c_str());
+ AFB_WARNING("erase application(%s) wasn't in applist.", appid.c_str());
}
}
*/
void HS_AppInfo::pushAppListChangedEvent(const char *oper, struct json_object *object)
{
- HMI_NOTICE("homescreen-service","called.");
struct json_object *push_obj = json_object_new_object();
json_object_object_add(push_obj, _keyOperation, json_object_new_string(oper));
json_object_object_add(push_obj, _keyData, object);
struct json_object *obj = json_object_array_get_idx(obj_runnables, i);
struct json_object *j_id;
if(json_object_object_get_ex(obj, _keyId, &j_id) == 0) {
- HMI_WARNING("homescreen-service","can't find id.");
+ AFB_WARNING("can't find id.");
continue;
}
if(id == json_object_get_string(j_id)) {
}
}
else {
- HMI_ERROR("homescreen-service","Apps information input error.");
+ AFB_ERROR("Apps information input error.");
}
return j_found;
}
{
std::string appid;
std::size_t pos = id.find("@");
- if(pos != std::string::npos) {
- appid = id.substr(0,pos);
- }
- else {
- HMI_ERROR("homescreen-service","input id error.");
- }
+ appid = id.substr(0,pos);
return appid;
}
void HS_AppInfo::getRunnables(struct json_object **object)
{
if(json_object_get_type(*object) != json_type_array) {
- HMI_ERROR("homescreen-service","json type error.");
+ AFB_ERROR("json type error.");
return;
}