On date Monday 2008-09-08 10:08:39 +0200, Stefano Sabatini wrote:
> On date Friday 2008-09-05 12:10:10 +0200, Stefano Sabatini wrote:
> > On 9/5/08, Stefano Sabatini <[EMAIL PROTECTED]> wrote:
> > > Hi all,
> > >
> > > I have a multithreaded application, and I need to run the sofia-sip
> > > event loop not in the main process context, but in the context of a
> > > thread.
> > >
> > > I implemented it this way.
> > > I implemented a method Run() which instantiates the thread instance
> > > and makes it execute su_root_run(),  and a Stop() method which
> > > executes su_root_break() and wait for the thread termination.
> > >
> > > Unfortunately this approach seems not to work, as I get this message
> > > from the sofia stack:
> > > nua(0x8729740): signal r_invite
> > > SIPEngineTest: su_base_port.c:322: su_base_port_run: Assertion
> > > `su_port_own_thread(self)' failed.
> > >
> > > and the process gets terminated by the SIGABRT signal.
> > >
> > > I'm currently stuck with it, can someone help/provide some hint?
> > 
> > Do I need to use the interface defined in su_wait.h?
> > I was using the functions provided in another library for managing 
> > threading.
> 
> Well I read the documentation for su_wait.h but I stll can't figure
> out how to use it.
> 
> Since there is no way to create explicitly a thread, I think the
> nearest think to the thread concept is the task, then I can't see any
> reference to mutexes so I have no idea about how synchronization may
> work here (mmh well should I use messages for that?).
> 
> Please can someone suggest just a simple way to use the sofia API to
> create and run a thread?

Here it is my first attempt at sofia threading:

----------------------------------------------8<-------------------------
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>

/* this defines the kind of magic to pass to the handler, contains the 
application context */
#define SU_ROOT_MAGIC_T void

#include <sofia-sip/su.h>
#include <sofia-sip/su_wait.h>

int countdown_init(su_root_t* root, su_root_magic_t* magic)
{
    int i;
    printf("click clack click clack...\n");
    for (i=10; i > 0; i--) {
        sleep(1);
        printf("%d...\n", i);
    }
    return 0;
}

void countdown_deinit(su_root_t* root, su_root_magic_t* magic)
{
    printf("BOOM...\n");
}

int main (int argc, char *argv[])
{
    su_root_t *root;

    /* Initialize Sofia-SIP library and create event loop */
    su_init();

    root = su_root_create(NULL); /* create a root object, don't pass to it any 
context */

    /* enable threading, now su_clone_start will start a new thread */
    if (!su_root_threading(root, 1)) {
        fprintf(stderr, "Failed to activate threading\n");
        exit(1);
    }

    su_clone_r clone;
    /* this is blocking */
    su_clone_start(root,
                   clone,
                   NULL,
                   &countdown_init,
                   &countdown_deinit);

    printf("main process thread...\n");

    /* Destroy allocated resources */
    su_root_destroy(root);
    su_deinit();

    exit(0);
}
----------------------------------------------8<-------------------------

And this is the output:
click clack click clack...
10...
9...
8...
7...
6...
5...
4...
3...
2...
1...
main process thread...

In this case the call to the countdown_init function is blocking,
furthermore the countdown_deinit function is not called at all.

What (possbily silly) am I missing?

TIA, regards.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to