< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate] Call Forking


Can any body help me in how to fork the call to two different devices in
the Proxy. I have tried many things but i am unable to send two requests
at a time. I am attaching the source code also.

Please help me in this matter.
Thanks in advance
Santosh
#include "iostream.h"

#include "resiprocate/Helper.hxx"
#include "resiprocate/SipMessage.hxx"
#include "resiprocate/Uri.hxx"
#include "resiprocate/SipStack.hxx"
#include "resiprocate/DeprecatedDialog.hxx"
#include "resiprocate/os/Logger.hxx"
#include "resiprocate/os/ThreadIf.hxx"
#include "resiprocate/SdpContents.hxx"

using namespace resip;
using namespace std;


void * sendRequest(void *);

SipStack sipStack;
class SipProxy
{
        private:
                SipMessage *request1,*request2;
                pthread_t thread1,thread2;
                int iret1,iret2;

        public:
                SipProxy();
                void buildFdSet(FdSet& fdset);
                void process(FdSet& fdset);
                void processRequest( SipMessage* );
                void processResponse( SipMessage* );
};

SipProxy::SipProxy()
{       
        //sipStack.addTransport(UDP,5070);
        sipStack.addTransport(UDP,5060);
}

void SipProxy::buildFdSet(FdSet& fdset)
{
        sipStack.buildFdSet(fdset);
}

void SipProxy::process(FdSet& fdset)
{
        sipStack.process(fdset);
        SipMessage *received_message = sipStack.receive();
        if(received_message)
        {
                if(received_message->isRequest())
                {
                        processRequest(received_message);
                }
                else
                if(received_message->isResponse())
                {
                        processResponse(received_message);
                }
        }
}

void SipProxy::processRequest(SipMessage *request_received)
{
        if( request_received->header(h_RequestLine).method() == INVITE )
        {
                Uri new_uri;
                Uri received_uri = 
request_received->header(h_RequestLine).uri();
                Data username = received_uri.user();
                Data hostname = received_uri.host();

                --request_received->header(h_MaxForwards).value();

                Via via;
                via.sentHost() = "192.168.1.201";
                via.sentPort() = 5060;
                via.transport() = "UDP";
                request_received->header(h_Vias).push_back(via);

                if(username=="sipphone" && hostname == "idealabs.com")
                {
                        request_received->header(h_RequestLine).uri().user() = 
"sipphone";
                        request_received->header(h_RequestLine).uri().host() = 
"192.168.1.10";
                        request_received->header(h_RequestLine).uri().port() = 
5060;
                        
                        iret1=pthread_create( &thread1, NULL,sendRequest, (void 
*) request_received);
                        //pthread_join(thread1,NULL);
                        
                        request_received->header(h_RequestLine).uri().host() = 
"192.168.1.11";
                        iret2=pthread_create( &thread2, NULL,sendRequest, (void 
*) request_received);
                        //pthread_join(thread2,NULL);
                }

        }
}

void *sendRequest(void *request)
{
        SipMessage *ptr=(SipMessage *)request;
        cout<<*ptr;
        sipStack.send(*ptr);
        cout<<"Request Sent"<<endl;
}


void SipProxy::processResponse(SipMessage *response_received)
{
        cout<<*response_received;
        //sipStack.send(*response_received);
}

int main(int argc, char *argv[])
{
        SipProxy sipProxy;
        while(true)
        {
                FdSet fdset;
                sipProxy.buildFdSet(fdset);
                fdset.selectMilliSeconds(100000000);
                sipProxy.process(fdset);
        }
        return 1;
}