Source code formating unification
[platform/framework/web/wrt-plugins-common.git] / src / wrt-popup / ace / popup-bin / Popup.cpp
index 16b0640..a3baeb6 100644 (file)
@@ -20,7 +20,8 @@
  */
 
 /*
- * This is just a example pop-up that shows how to use a new C-API in wrt-security.
+ * This is just a example pop-up that shows how to use a new C-API in
+ * wrt-security.
  * This pop-up should be re-implemented by members of NGWAP.
  */
 
 #include "Popup.h"
 
 namespace { // anonymous
-
-static void set_validity_from_checkbox(struct ace_popup_data *pdp) {
-
-    if(NULL == pdp){
+static void set_validity_from_checkbox(struct ace_popup_data *pdp)
+{
+    if (NULL == pdp) {
         LogError("pdp is NULL; return");
         return;
     }
@@ -65,20 +65,23 @@ static void set_validity_from_checkbox(struct ace_popup_data *pdp) {
     return;
 }
 
-static void on_done(void) {
+static void on_done(void)
+{
     // Quit the efl-mainloop
     LogDebug("elm_exit()");
     elm_exit();
 }
 
-static void grant_answer(void *data, Evas_Object * /* obj */, void * /* event_info */) {
-
+static void grant_answer(void *data,
+                         Evas_Object * /* obj */,
+                         void * /* event_info */)
+{
     LogDebug("grant_answer");
-    if(NULL == data){
+    if (NULL == data) {
         LogError("data is NULL; return");
         return;
     }
-    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *> (data);
+    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *>(data);
 
     set_validity_from_checkbox(pdp);
 
@@ -96,14 +99,16 @@ static void grant_answer(void *data, Evas_Object * /* obj */, void * /* event_in
     on_done();
 }
 
-static void deny_answer(void *data, Evas_Object * /* obj */, void * /* event_info */) {
-
+static void deny_answer(void *data,
+                        Evas_Object * /* obj */,
+                        void * /* event_info */)
+{
     LogDebug("deny_answer");
-    if(NULL == data){
+    if (NULL == data) {
         LogError("data is NULL; return");
         return;
     }
-    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *> (data);
+    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *>(data);
 
     set_validity_from_checkbox(pdp);
 
@@ -121,11 +126,12 @@ static void deny_answer(void *data, Evas_Object * /* obj */, void * /* event_inf
     on_done();
 }
 
-static int _ace_params_deserializer(ace_param_list_t* ace_param_list, Wrt::Popup::BinaryStream *stream){
-
+static int _ace_params_deserializer(ace_param_list_t* ace_param_list,
+                                    Wrt::Popup::BinaryStream *stream)
+{
     LogDebug("_ace_params_deserializer");
 
-    if(NULL == ace_param_list || NULL == stream){
+    if (NULL == ace_param_list || NULL == stream) {
         LogError("ace_param_list or stream is NULL; return -1");
         return -1;
     }
@@ -138,26 +144,28 @@ static int _ace_params_deserializer(ace_param_list_t* ace_param_list, Wrt::Popup
 
     std::string name;
     std::string value;
-    if(count == 0){
+    if (count == 0) {
         ace_param_list->items = NULL;
         return 0;
     }
-    ace_param_list->items = static_cast <ace_param_t *> (malloc(count * sizeof(ace_param_t)));
+    ace_param_list->items =
+        static_cast <ace_param_t *>(malloc(count * sizeof(ace_param_t)));
     memset(ace_param_list->items, 0, count * sizeof(ace_param_t));
 
-    for(size_t i=0; i < count; ++i){
+    for (size_t i = 0; i < count; ++i) {
         DPL::Deserialization::Deserialize(*stream, name);
         ace_param_list->items[i].name =
-                strdup(const_cast <char *> (name.c_str()));
+            strdup(const_cast <char *>(name.c_str()));
 
         DPL::Deserialization::Deserialize(*stream, value);
         ace_param_list->items[i].value =
-                strdup(const_cast <char *> (value.c_str()));
+            strdup(const_cast <char *>(value.c_str()));
     }
     return 0;
 }
 
-static void _ace_params_finalize(ace_param_list_t* ace_param_list) {
+static void _ace_params_finalize(ace_param_list_t* ace_param_list)
+{
     if (!ace_param_list || !ace_param_list->items) {
         LogDebug("List is null, nothing to do");
         return;
@@ -171,25 +179,26 @@ static void _ace_params_finalize(ace_param_list_t* ace_param_list) {
     ace_param_list->count = 0;
 }
 
-static void show_popup(struct ace_popup_data *pdp) {
+static void show_popup(struct ace_popup_data *pdp)
+{
     LogDebug("show_popup()");
 
-    if(NULL == pdp){
+    if (NULL == pdp) {
         LogError("pdp is NULL; return");
         return;
     }
 
-    const char *resource_type = static_cast <char *> (pdp->resource_name);
+    const char *resource_type = static_cast <char *>(pdp->resource_name);
 
-    Evas_Object *win          = NULL;
-    Evas_Object *cb_session   = NULL;
-    Evas_Object *cb_always    = NULL;
-    Evas_Object *box          = NULL;
-    Evas_Object *label        = NULL;
+    Evas_Object *win = NULL;
+    Evas_Object *cb_session = NULL;
+    Evas_Object *cb_always = NULL;
+    Evas_Object *box = NULL;
+    Evas_Object *label = NULL;
     Evas_Object *grant_button = NULL;
-    Evas_Object *deny_button  = NULL;
-    pdp->per_session          = EINA_FALSE;
-    pdp->always               = EINA_FALSE;
+    Evas_Object *deny_button = NULL;
+    pdp->per_session = EINA_FALSE;
+    pdp->always = EINA_FALSE;
 
     win = elm_win_add(NULL, "The wrt-client popup", ELM_WIN_NOTIFICATION);
     elm_win_autodel_set(win, EINA_TRUE);
@@ -207,7 +216,10 @@ static void show_popup(struct ace_popup_data *pdp) {
     elm_object_style_set(label, "popup_description/default");
     elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
     char *buff = NULL;
-    if(-1 == asprintf(&buff, "Application need an access to %s.<br>Grant or deny?", resource_type)){
+    if (-1 ==
+        asprintf(&buff, "Application need an access to %s.<br>Grant or deny?",
+                 resource_type))
+    {
         LogError("asprintf failed - returned -1");
         evas_object_del(label);
         evas_object_del(pdp->popup);
@@ -228,8 +240,12 @@ static void show_popup(struct ace_popup_data *pdp) {
         elm_object_text_set(cb_session, "Remember choice for this session");
         elm_check_state_pointer_set(cb_session, &(pdp->per_session));
         evas_object_smart_callback_add(cb_session, "changed", NULL, NULL);
-        evas_object_size_hint_align_set(cb_session, EVAS_HINT_FILL, EVAS_HINT_FILL);
-        evas_object_size_hint_weight_set(cb_session, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+        evas_object_size_hint_align_set(cb_session,
+                                        EVAS_HINT_FILL,
+                                        EVAS_HINT_FILL);
+        evas_object_size_hint_weight_set(cb_session,
+                                         EVAS_HINT_EXPAND,
+                                         EVAS_HINT_EXPAND);
         evas_object_show(cb_session);
         elm_box_pack_end(box, cb_session);
 
@@ -239,8 +255,12 @@ static void show_popup(struct ace_popup_data *pdp) {
             elm_object_text_set(cb_always, "Remember choice forever");
             elm_check_state_pointer_set(cb_always, &(pdp->always));
             evas_object_smart_callback_add(cb_always, "changed", NULL, NULL);
-            evas_object_size_hint_align_set(cb_always, EVAS_HINT_FILL, EVAS_HINT_FILL);
-            evas_object_size_hint_weight_set(cb_always, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+            evas_object_size_hint_align_set(cb_always,
+                                            EVAS_HINT_FILL,
+                                            EVAS_HINT_FILL);
+            evas_object_size_hint_weight_set(cb_always,
+                                             EVAS_HINT_EXPAND,
+                                             EVAS_HINT_EXPAND);
             evas_object_show(cb_always);
             elm_box_pack_end(box, cb_always);
         }
@@ -266,23 +286,21 @@ static void show_popup(struct ace_popup_data *pdp) {
     // Run the efl mainloop
     elm_run();
 }
-
 } // anonymous
 
-
 EAPI_MAIN int
-elm_main(int argc , char ** argv)
+elm_main(int argc, char ** argv)
 {
     UNHANDLED_EXCEPTION_HANDLER_BEGIN
     {
-// int pipe_in and int pipe_out should be passed to Popup via args.
+        // int pipe_in and int pipe_out should be passed to Popup via args.
 
-//  These parameters should be passed to Popup via pipe:
-//  ace_popup_t             popup_type
-//  const ace_resource_t    resource_name
-//  const ace_session_id_t  session_id
-//  ace_widget_handle_t     handle
-//  const ace_param_list_t  param_list
+        //  These parameters should be passed to Popup via pipe:
+        //  ace_popup_t             popup_type
+        //  const ace_resource_t    resource_name
+        //  const ace_session_id_t  session_id
+        //  ace_widget_handle_t     handle
+        //  const ace_param_list_t  param_list
 
         try {
             DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP-BIN");
@@ -290,31 +308,34 @@ elm_main(int argc , char ** argv)
             //cannot run logger
             return ACE_INTERNAL_ERROR;
         }
-        LogDebug("############################ popup binary ################################");
+        LogDebug(
+            "############################ popup binary ################################");
 
-        if(argc < 3){
-            LogError("To few args passed in exec to popup-bin - should be at least 3:");
+        if (argc < 3) {
+            LogError(
+                "To few args passed in exec to popup-bin - should be at least 3:");
             LogError("(binary-name, pipe_in, pipe_out)");
             LogError("return ACE_INTERNAL_ERROR");
             return ACE_INTERNAL_ERROR;
         }
-        LogDebug("Passed args: " << argv[0] <<", " << argv[1] << ", " << argv[2]);
+        LogDebug("Passed args: " << argv[0] << ", " << argv[1] << ", " <<
+                 argv[2]);
 
         int pipe_in;
         int pipe_out;
 
         // Parsing args (pipe_in, pipe_out)
-        if ( 0 == sscanf(argv[1], "%d", &pipe_in) ){
+        if (0 == sscanf(argv[1], "%d", &pipe_in) ) {
             LogError("Error while parsing pipe_in; return ACE_INTERNAL_ERROR");
             return ACE_INTERNAL_ERROR;
         }
-        if ( 0 == sscanf(argv[2], "%d", &pipe_out) ){
+        if (0 == sscanf(argv[2], "%d", &pipe_out) ) {
             LogError("Error while parsing pipe_out; return ACE_INTERNAL_ERROR");
             return ACE_INTERNAL_ERROR;
         }
-        LogDebug("Parsed pipes: IN: " << pipe_in <<", OUT: " <<  pipe_out);
+        LogDebug("Parsed pipes: IN: " << pipe_in << ", OUT: " << pipe_out);
 
-        int  buff_size = 1024;
+        int buff_size = 1024;
         char line[buff_size];
 
         struct ace_popup_data pd;
@@ -330,26 +351,27 @@ elm_main(int argc , char ** argv)
         // timeout is set for 10 seconds
         do {
             count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size));
-            if ( timeout < difftime(time(NULL), time_start) ) {
+            if (timeout < difftime(time(NULL), time_start) ) {
                 LogError("Timeout reached! Exit popup - ACE_INTERNAL_ERROR");
                 close(pipe_in);
                 close(pipe_out);
                 return ACE_INTERNAL_ERROR;
             }
         } while (0 == count);
-        if(count < 0){
+        if (count < 0) {
             close(pipe_in);
             close(pipe_out);
-            LogError("read returned a negative value (" << count <<")");
-            LogError("errno: " << strerror( errno ) );
+            LogError("read returned a negative value (" << count << ")");
+            LogError("errno: " << strerror(errno) );
             LogError("Exit popup - ACE_INTERNAL_ERROR");
             return ACE_INTERNAL_ERROR;
         }
-        LogDebug("Read bytes : " << count << " (in " << difftime(time_start, time(NULL)) << " seconds)");
+        LogDebug("Read bytes : " << count << " (in " <<
+                 difftime(time_start, time(NULL)) << " seconds)");
         close(pipe_in); // cleanup
 
         Wrt::Popup::BinaryStream stream;
-        stream.Write(count, static_cast <void *> (line));
+        stream.Write(count, static_cast <void *>(line));
         int popup_type = ACE_ONESHOT;
         std::string resource_name_str;
         std::string session_id_str;
@@ -361,23 +383,23 @@ elm_main(int argc , char ** argv)
 
         DPL::Deserialization::Deserialize(stream, popup_type);
         LogDebug("popup_type_int : " << popup_type);
-        pdp->popup_type = static_cast <ace_popup_t> (popup_type);
+        pdp->popup_type = static_cast <ace_popup_t>(popup_type);
 
         DPL::Deserialization::Deserialize(stream, resource_name_str);
         LogDebug("resource_name_char : " << resource_name_str.c_str());
         pdp->resource_name =
-                strdup(const_cast <ace_resource_t> (resource_name_str.c_str()));
+            strdup(const_cast <ace_resource_t>(resource_name_str.c_str()));
 
         DPL::Deserialization::Deserialize(stream, session_id_str);
         LogDebug("session_id_char : " << session_id_str.c_str());
         pdp->session_id =
-                strdup(const_cast <ace_session_id_t> (session_id_str.c_str()));
+            strdup(const_cast <ace_session_id_t>(session_id_str.c_str()));
 
         DPL::Deserialization::Deserialize(stream, handle);
         LogDebug("handle_int : " << handle);
-        pdp->handle = static_cast <ace_widget_handle_t> (handle);
+        pdp->handle = static_cast <ace_widget_handle_t>(handle);
 
-        if(_ace_params_deserializer(&(pdp->param_list), &stream)){
+        if (_ace_params_deserializer(&(pdp->param_list), &stream)) {
             return ACE_INTERNAL_ERROR;
         }
 
@@ -394,7 +416,10 @@ elm_main(int argc , char ** argv)
         int validation_result_int = (int) pdp->validation_result;
         LogDebug("validation_result_int : " << validation_result_int);
         DPL::Serialization::Serialize(stream_out, validation_result_int);
-        if(-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))){
+        if (-1 ==
+            TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(),
+                                     stream_out.size())))
+        {
             LogError("Write to pipe failed!");
             close(pipe_out);
             return ACE_INTERNAL_ERROR;
@@ -403,27 +428,26 @@ elm_main(int argc , char ** argv)
 
         if (pdp->validation_return == ACE_OK) {
             LogDebug("ACE_OK");
-        }
-        else if (pdp->validation_return == ACE_INVALID_ARGUMENTS) {
+        } else if (pdp->validation_return == ACE_INVALID_ARGUMENTS) {
             LogError("ACE_INVALID_ARGUMENTS");
-        }
-        else if (pdp->validation_return == ACE_INTERNAL_ERROR) {
+        } else if (pdp->validation_return == ACE_INTERNAL_ERROR) {
             LogError("ACE_INTERNAL_ERROR");
-        }
-        else if (pdp->validation_return == ACE_ACE_UNKNOWN_ERROR) {
+        } else if (pdp->validation_return == ACE_ACE_UNKNOWN_ERROR) {
             LogError("ACE_ACE_UNKNOWN_ERROR");
-        }
-        else {
+        } else {
             LogError("Really unknown error!!!");
         }
 
-        LogDebug("############################ /popup binary ################################");
+        LogDebug(
+            "############################ /popup binary ################################");
 
         // Shutdown elementary
         //LogDebug("elm_shutdown()");
         //elm_shutdown();
-        // This is commented because, it causes that popup exits with 139 code (Segmentatation violation).
-        // Not calling elm_shutdown() should not have any negative consequences because this binary ends
+        // This is commented because, it causes that popup exits with 139 code
+        // (Segmentatation violation).
+        // Not calling elm_shutdown() should not have any negative consequences
+        // because this binary ends
         // in next line, and system should clear the memory.
 
         _ace_params_finalize(&(pdp->param_list));