<div dir="ltr">Hi Andrey,<br><div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for the patch, but I hate to spoil it for you ;) <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 26, 2013 at 8:09 PM, Andrey Utkin <span dir="ltr"><<a href="mailto:andrey.krieger.utkin@gmail.com" target="_blank">andrey.krieger.utkin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This does not break original dvbpsi_new() mechanism.<br>
Rationale: when dvbpsi contexts are created in many objects, you may<br>
need to figure out, which object is the owner.<br>
---<br>
 src/dvbpsi.c | 19 +++++++++++++++++++<br>
 src/dvbpsi.h |  8 ++++++++<br>
 2 files changed, 27 insertions(+)<br></blockquote><div><br>The functionality you require is already present in libdvbpsi in the form <br>of a private pointer inside the dvbpsi_t structure, from dvbpsi.h header file:<br>
<br>/*****************************************************************************<br> * dvbpsi_t<br> *****************************************************************************/<br>/*!<br> * \struct dvbpsi_s<br> * \brief DVBPSI handle structure<br>
 *<br> * This structure provides a handle to libdvbpsi API and should be used instead<br> * of dvbpsi_decoder_t.<br> */<br>/*!<br> * \typedef struct dvbpsi_s dvbpsi_t<br> * \brief dvbpsi_t type definition.<br> */<br>struct dvbpsi_s<br>
{<br>    dvbpsi_decoder_t             *p_decoder;          /*!< private pointer to<br>                                                          specific decoder */<br>    /* Messages callback */<br>    dvbpsi_message_cb             pf_message;           /*!< Log message callback */<br>
    enum dvbpsi_msg_level         i_msg_level;          /*!< Log level */<br><br>    /* private data pointer for use by caller, not by libdvbpsi itself ! */<br>    void                         *p_sys;                /*!< pointer to private data<br>
                                                          from caller. Do not use<br>                                                          from inside libdvbpsi. It<br>                                                          will crash any application. */<br>
};<br> <br><div class="gmail_extra">The p_sys pointer can be used to attach your context. I think the documentation for this could be improved,<br></div><div class="gmail_extra">since you missed this use case.<br><br></div>
<div class="gmail_extra">In addtion each PSI table attache function "dvbpsi_XXX_attach()" also allows for passing private data to the callback function.  The<br>example program dvbinfo makes use of this mechanism to pass on a 'context'. The function<br>
libdvbpsi_init() shows you how to use this, eg: lines 1747 (dvbpsi_pat_attach function), 648 (PAT callback function) <br></div><br></div><div>Kind regards,<br></div><div>Jean-Paul Saman.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<br>
diff --git a/src/dvbpsi.c b/src/dvbpsi.c<br>
index 4d27720..e9a9ad9 100644<br>
--- a/src/dvbpsi.c<br>
+++ b/src/dvbpsi.c<br>
@@ -60,6 +60,19 @@ dvbpsi_t *dvbpsi_new(dvbpsi_message_cb callback, enum dvbpsi_msg_level level)<br>
     return p_dvbpsi;<br>
 }<br>
<br>
+dvbpsi_t *dvbpsi_new2(void *context, dvbpsi_message_cb2 callback, enum dvbpsi_msg_level level)<br>
+{<br>
+    dvbpsi_t *p_dvbpsi = calloc(1, sizeof(dvbpsi_t));<br>
+    if (p_dvbpsi == NULL)<br>
+        return NULL;<br>
+<br>
+    p_dvbpsi->p_decoder  = NULL;<br>
+    p_dvbpsi->context = context;<br>
+    p_dvbpsi->pf_message2 = callback;<br>
+    p_dvbpsi->i_msg_level = level;<br>
+    return p_dvbpsi;<br>
+}<br>
+<br>
 /*****************************************************************************<br>
  * dvbpsi_delete<br>
  *****************************************************************************/<br>
@@ -537,6 +550,8 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char<br>
         if (err > DVBPSI_MSG_NONE) {<br>
             if (dvbpsi->pf_message)<br>
                 dvbpsi->pf_message(dvbpsi, level, msg);<br>
+            else if (dvbpsi->pf_message2)<br>
+                dvbpsi->pf_message2(dvbpsi->context, dvbpsi, level, msg);<br>
         }<br>
         free(msg);<br>
     }<br>
@@ -563,6 +578,8 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char<br>
         if (err > 0) {                                          \<br>
             if (dvbpsi->pf_message)                             \<br>
                 dvbpsi->pf_message(dvbpsi, level, msg);         \<br>
+            else if (dvbpsi->pf_message2)                       \<br>
+                dvbpsi->pf_message2(dvbpsi->context, dvbpsi, level, msg);\<br>
         }                                                       \<br>
         free(msg);                                              \<br>
     } while(0);<br>
@@ -581,6 +598,8 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char<br>
         if (err > 0) {                                          \<br>
             if (dvbpsi->pf_message)                             \<br>
                 dvbpsi->pf_message(dvbpsi, level, msg);         \<br>
+            else if (dvbpsi->pf_message2)                       \<br>
+                dvbpsi->pf_message2(dvbpsi->context, dvbpsi, level, msg);\<br>
         }                                                       \<br>
         free(msg);                                              \<br>
     } while(0);<br>
diff --git a/src/dvbpsi.h b/src/dvbpsi.h<br>
index 062a9db..cb28b96 100644<br>
--- a/src/dvbpsi.h<br>
+++ b/src/dvbpsi.h<br>
@@ -95,6 +95,11 @@ typedef void (* dvbpsi_message_cb)(dvbpsi_t *handle,<br>
                                    const dvbpsi_msg_level_t level,<br>
                                    const char* msg);<br>
<br>
+typedef void (* dvbpsi_message_cb2)(void *context,<br>
+                                    dvbpsi_t *handle,<br>
+                                    const dvbpsi_msg_level_t level,<br>
+                                    const char* msg);<br>
+<br>
 /*****************************************************************************<br>
  * dvbpsi_decoder_t<br>
  *****************************************************************************/<br>
@@ -145,6 +150,8 @@ struct dvbpsi_s<br>
                                                           specific decoder */<br>
     /* Messages callback */<br>
     dvbpsi_message_cb             pf_message;           /*!< Log message callback */<br>
+    void                         *context;<br>
+    dvbpsi_message_cb2            pf_message2;          /*!< Log message callback */<br>
     enum dvbpsi_msg_level         i_msg_level;          /*!< Log level */<br>
<br>
     /* private data pointer for use by caller, not by libdvbpsi itself ! */<br>
@@ -169,6 +176,7 @@ struct dvbpsi_s<br>
  * handle must be freed with dvbpsi_delete().<br>
  */<br>
 dvbpsi_t *dvbpsi_new(dvbpsi_message_cb callback, enum dvbpsi_msg_level level);<br>
+dvbpsi_t *dvbpsi_new2(void *context, dvbpsi_message_cb2 callback, enum dvbpsi_msg_level level);<br>
<br>
 /*****************************************************************************<br>
  * dvbpsi_delete<br>
<span class=""><font color="#888888">--<br>
1.8.1.5<br>
<br>
_______________________________________________<br>
libdvbpsi-devel mailing list<br>
<a href="mailto:libdvbpsi-devel@videolan.org">libdvbpsi-devel@videolan.org</a><br>
<a href="http://mailman.videolan.org/listinfo/libdvbpsi-devel" target="_blank">http://mailman.videolan.org/listinfo/libdvbpsi-devel</a><br>
</font></span></blockquote></div><br></div></div></div>