/////////////////////////////////////////////////////////////////////////////////File Name: TRIPThread.cpp//Description: Launches a TRIP thread from within SIPD.///////////////////////////////////////////////////////////////////////////////#include <sys/time.h>#include <pthread.h>#include <string>#include <sstream>#include <unistd.h>#include <stdlib.h>#include <iostream.h>#ifdef __linux__    #include <getopt.h>#endif#include "tripthread.h"#include "LSLocator.hxx"#include "ProvisionInterface.hxx"#include "LSSessionManager.hxx"#include "cpLog.h"/////////////////////////////////////////////////////////////////////////////////METHOD DEFINITIONS///////////////////////////////////////////////////////////////////////////////static bool oStarted = false;extern "C" void *TRIPThread(void * p){  struct trip_thread_arg *arg = (trip_thread_arg *) p;  char * mode = "sendrec";  if (oStarted) {    cout << "TRIPThread is already started. Ignoring..." << endl;    return NULL;  }  oStarted = true;  cpLogSetPriority(cpLogStrToPriority("LOG_DEBUG"));  cout << "Starting LS with PS: " <<  arg->host << ", " << arg->port << endl;  LSSessionManager& manager = LSSessionManager::instance();  manager.init(arg->host);  manager.threadRun();  //This is to keep the thread alive.  //  while(1){    sleep(2);  }//End of while.  return NULL;}//-----------------------------------------------------------------------------                                                     extern "C" char * get_trip_route(char * dest) {  string destination(dest);  string gatewayFound = LSSessionManager::instance().findSIPGateway(destination);  char * ret = (char *) gatewayFound.c_str();  if (ret && *ret) {    ret = strdup(ret);    cout << "Found" << ret << endl;  }  else {    cout << "Not found" << endl;    ret = NULL;  }  return ret;}#if 0//-----------------------------------------------------------------------------                                                     tripthread::tripthread(void){  started = FALSE;  detached = FALSE;}//-----------------------------------------------------------------------------                                                     tripthread::~tripthread(void){  stop();}//-----------------------------------------------------------------------------                                                     int tripthread::start(void * param){  if(!started){    pthread_attr_t attributes;    pthread_attr_init(&attributes);    if(detached){      pthread_attr_setdetachedstate(&attributes, PTHREAD_CREATE_DETACHED);    }    param = param;    threadID = 0;    if(pthread_create(&threadHandle, &attributes, TRIPThread, this)==0){      started = TRUE;      pthread_attr_destroy(&attributes);  }  return started;}//-----------------------------------------------------------------------------                                                     static void * TRIPThread(void * object){  tripthread* thread = (tripthread*)object;  return thread->run(thread->param);}//-----------------------------------------------------------------------------                                                     void * tripthread::run(void * param){  return NULL;}//-----------------------------------------------------------------------------                                                     void tripthread::detach(void){  if(started && !detached){    pthread_detached(threadHandle);  }  detached = TRUE;}//-----------------------------------------------------------------------------                                                     void * tripthread::wait(void){  void * status = NULL;  if(started && !detached){    pthread_join(threadHandle, &status);    detached = TRUE;  }  return status;}//-----------------------------------------------------------------------------                                                     void tripthread::stop(void){  if(started && !detached){    pthread_cancel(threadHandle);    pthread_detach(threadHandle);    detached = TRUE;  }}//-----------------------------------------------------------------------------                                                     unsigned int tripthread::getThreadID(void){  return threadID;}//-----------------------------------------------------------------------------                                                     unsigned int tripthread::getCurrentThreadID(void){  return 0;}//-----------------------------------------------------------------------------                                                     void tripthread::sleep(int delay){  timeval timeout = {(delay/1000), ((delay*1000)%(1000000))};  select(0, (fd_set *)NULL, (fd_set *)NULL, (fd_set*)NULL, &timeout);}#endif///////////////////////////////////////////////////////////////////////////////                                                     