Add data to opcode registration callback
authorDaniel Zaoui <daniel.zaoui@yahoo.com>
Fri, 19 May 2017 05:59:56 +0000 (08:59 +0300)
committerDaniel Zaoui <daniel.zaoui@yahoo.com>
Mon, 5 Jun 2017 05:55:37 +0000 (08:55 +0300)
src/bin/efl/efl_debug.c
src/lib/eina/eina_debug.c
src/lib/eina/eina_debug.h
src/lib/eina/eina_debug_bt.c
src/lib/eina/eina_debug_cpu.c
src/lib/eina/eina_evlog.c

index 7876a08..1dff987 100644 (file)
@@ -208,7 +208,7 @@ _disp_cb(Eina_Debug_Session *session EINA_UNUSED, void *buffer)
 }
 
 static void
-_args_handle(Eina_Bool flag)
+_args_handle(void *data EINA_UNUSED, Eina_Bool flag)
 {
    if (!flag) exit(0);
    eina_debug_session_dispatch_override(_session, _disp_cb);;
@@ -254,7 +254,7 @@ main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
         fprintf(stderr, "ERROR: Cannot connect to debug daemon.\n");
         return -1;
      }
-   eina_debug_opcodes_register(_session, ops, _args_handle);
+   eina_debug_opcodes_register(_session, ops, _args_handle, NULL);
 
    ecore_main_loop_begin();
 
index 4517c6e..7acd7fb 100644 (file)
@@ -104,6 +104,7 @@ typedef struct
 {
    const Eina_Debug_Opcode *ops;
    Eina_Debug_Opcode_Status_Cb status_cb;
+   void *status_data;
 } _opcode_reply_info;
 
 struct _Eina_Debug_Session
@@ -117,6 +118,7 @@ struct _Eina_Debug_Session
                      * with the daemon. Only used when a shell remote
                      * connection is requested.
                      */
+   void *data; /* User data */
    double encoding_ratio; /* Encoding ratio */
    int cbs_length; /* cbs table size */
    int fd_in; /* File descriptor to read */
@@ -548,7 +550,7 @@ _callbacks_register_cb(Eina_Debug_Session *session, int src_id EINA_UNUSED, void
                   _static_opcode_register(session, os[i], info->ops[i].cb);
                   e_debug("Opcode %s -> %d", info->ops[i].opcode_name, os[i]);
                }
-             if (info->status_cb) info->status_cb(EINA_TRUE);
+             if (info->status_cb) info->status_cb(info->status_data, EINA_TRUE);
              return EINA_DEBUG_OK;
           }
      }
@@ -623,7 +625,7 @@ _opcodes_unregister_all(Eina_Debug_Session *session)
              if (op->opcode_id) *(op->opcode_id) = EINA_DEBUG_OPCODE_INVALID;
              op++;
           }
-        if (info->status_cb) info->status_cb(EINA_FALSE);
+        if (info->status_cb) info->status_cb(info->status_data, EINA_FALSE);
      }
 }
 
@@ -685,7 +687,7 @@ eina_debug_local_connect(Eina_Bool is_master)
    _daemon_greet(session);
    _opcodes_register_all(session);
    if (!is_master)
-      eina_debug_opcodes_register(session, _MONITOR_OPS, NULL);
+      eina_debug_opcodes_register(session, _MONITOR_OPS, NULL, NULL);
 
    _last_local_session = session;
    return session;
@@ -777,7 +779,7 @@ eina_debug_shell_remote_connect(const char *cmds_str)
         eina_debug_session_shell_codec_enable(session);
         session->cmds = cmds;
         _cmd_consume(session);
-        eina_debug_opcodes_register(session, _BRIDGE_OPS, NULL);
+        eina_debug_opcodes_register(session, _BRIDGE_OPS, NULL, NULL);
         eina_debug_timer_add(10000, _bridge_keep_alive_send, session);
         // start the monitor thread
         _thread_start(session);
@@ -882,7 +884,7 @@ _thread_start(Eina_Debug_Session *session)
  */
 EAPI void
 eina_debug_opcodes_register(Eina_Debug_Session *session, const Eina_Debug_Opcode ops[],
-      Eina_Debug_Opcode_Status_Cb status_cb)
+      Eina_Debug_Opcode_Status_Cb status_cb, void *data)
 {
    if (!session) session = _last_local_session;
    if (!session) return;
@@ -890,6 +892,7 @@ eina_debug_opcodes_register(Eina_Debug_Session *session, const Eina_Debug_Opcode
    _opcode_reply_info *info = malloc(sizeof(*info));
    info->ops = ops;
    info->status_cb = status_cb;
+   info->status_data = data;
 
    session->opcode_reply_infos = eina_list_append(
          session->opcode_reply_infos, info);
index a7caeca..e548df3 100644 (file)
@@ -79,9 +79,10 @@ typedef Eina_Debug_Error (*Eina_Debug_Cb)(Eina_Debug_Session *session, int srcid
  * layer should not try to send more requests until a new connection is
  * established.
  *
+ * @param data data pointer given when registering opcodes
  * @param status EINA_TRUE if opcodes have been received from the daemon, EINA_FALSE otherwise.
  */
-typedef void (*Eina_Debug_Opcode_Status_Cb)(Eina_Bool status);
+typedef void (*Eina_Debug_Opcode_Status_Cb)(void *data, Eina_Bool status);
 
 /**
  * @typedef Eina_Debug_Dispatch_Cb
@@ -263,9 +264,15 @@ EAPI void *eina_debug_session_data_get(Eina_Debug_Session *session);
  * the opcodes ids is sent.
  * On the reception from the daemon, status_cb function is invoked to inform
  * the requester that the opcodes can now be used.
+ *
+ * @param session the session
+ * @param ops the operations to register
+ * @param status_cb a function to call when the opcodes are received
+ * @param status_data the data to give to status_cb
  */
 EAPI void eina_debug_opcodes_register(Eina_Debug_Session *session,
-      const Eina_Debug_Opcode ops[], Eina_Debug_Opcode_Status_Cb status_cb);
+      const Eina_Debug_Opcode ops[],
+      Eina_Debug_Opcode_Status_Cb status_cb, void *status_data);
 
 /**
  * @brief Send a packet to the given destination
index 61a550b..12f830e 100644 (file)
@@ -214,7 +214,7 @@ Eina_Bool
 _eina_debug_bt_init(void)
 {
    eina_semaphore_new(&_wait_for_bts_sem, 0);
-   eina_debug_opcodes_register(NULL, _OPS, NULL);
+   eina_debug_opcodes_register(NULL, _OPS, NULL, NULL);
    return EINA_TRUE;
 }
 
index e864592..dcab372 100644 (file)
@@ -295,7 +295,7 @@ _eina_debug_cpu_init(void)
           }
         _sysmon_thread_runs = EINA_TRUE;
      }
-   eina_debug_opcodes_register(NULL, _OPS, NULL);
+   eina_debug_opcodes_register(NULL, _OPS, NULL, NULL);
    return EINA_TRUE;
 }
 
index 1d2183a..c5753af 100644 (file)
@@ -272,7 +272,7 @@ eina_evlog_init(void)
      }
 #endif
    eina_evlog("+eina_init", NULL, 0.0, NULL);
-   eina_debug_opcodes_register(NULL, _EINA_DEBUG_EVLOG_OPS, NULL);
+   eina_debug_opcodes_register(NULL, _EINA_DEBUG_EVLOG_OPS, NULL, NULL);
    return EINA_TRUE;
 }