Пример #1
0
/********************************************************************************
 * upnp_igd_start
 *
 * Description:
 *       Start uPnP IGD context.
 *
 * Parameters:
 *   igd_ctxt -- The upnp igd context
 *
 ********************************************************************************/
int upnp_igd_start(upnp_igd_context*igd_ctxt) {
	int ret;
	ithread_mutex_lock(&igd_ctxt->mutex);
	if(igd_ctxt->upnp_handle != -1) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_WARNING, "uPnP IGD client already started...");
		ithread_mutex_unlock(&igd_ctxt->mutex);
		return -1;
	}
	upnp_igd_print(igd_ctxt, UPNP_IGD_DEBUG, "uPnP IGD client registering...");
	ret = UpnpRegisterClient(upnp_igd_callback, igd_ctxt, &igd_ctxt->upnp_handle);
	if (ret != UPNP_E_SUCCESS) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "Error registering IGD client: %d", ret);
		ithread_mutex_unlock(&igd_ctxt->mutex);
		return ret;
	}

	upnp_igd_print(igd_ctxt, UPNP_IGD_MESSAGE, "uPnP IGD client registered");

	/* Initialize timer stuff */
	ithread_create(&igd_ctxt->timer_thread, NULL, upnp_igd_timer_loop, igd_ctxt);

	ithread_mutex_unlock(&igd_ctxt->mutex);
	
	ret = upnp_igd_refresh(igd_ctxt);
	
	return ret;
}
Пример #2
0
int main(int argc, char *argv[])
{
	int rc;
	ithread_t cmdloop_thread;
#ifdef WIN32
#else
	int sig;
	sigset_t sigs_to_catch;
#endif
	int code;

	rc = device_main(argc, argv);
	if (rc != UPNP_E_SUCCESS) {
		return rc;
	}

	/* start a command loop thread */
	code = ithread_create(&cmdloop_thread, NULL, TvDeviceCommandLoop, NULL);
	if (code !=  0) {
		return UPNP_E_INTERNAL_ERROR;
	}
#ifdef WIN32
	ithread_join(cmdloop_thread, NULL);
#else
	/* Catch Ctrl-C and properly shutdown */
	sigemptyset(&sigs_to_catch);
	sigaddset(&sigs_to_catch, SIGINT);
	sigwait(&sigs_to_catch, &sig);
	SampleUtil_Print("Shutting down on signal %d...\n", sig);
#endif
	rc = TvDeviceStop();

	return rc;
}
Пример #3
0
int
main( int argc,
      char **argv )
{
    int rc;
    ithread_t cmdloop_thread;
    int sig;
    sigset_t sigs_to_catch;
    int code;

    rc = TvCtrlPointStart( linux_print, NULL );
    if( rc != TV_SUCCESS ) {
        SampleUtil_Print( "Error starting UPnP TV Control Point" );
        exit( rc );
    }
    // start a command loop thread
    code =
        ithread_create( &cmdloop_thread, NULL, TvCtrlPointCommandLoop,
                        NULL );

    /*
       Catch Ctrl-C and properly shutdown 
     */
    sigemptyset( &sigs_to_catch );
    sigaddset( &sigs_to_catch, SIGINT );
    sigwait( &sigs_to_catch, &sig );

    SampleUtil_Print( "Shutting down on signal %d...", sig );
    rc = TvCtrlPointStop(  );
    exit( rc );
}
Пример #4
0
/*
	Fuction:UpLoad;
	INPUT:
		Command Sent to Server -- char*;
	RETURN:NULL;
*/
void SA_UpLoad(char* Command)
{
   ithread_t cmdloop_thread;

   strcpy(NowCommand , Command);

   ithread_create( &cmdloop_thread, NULL, SA_CommandLoop, NULL );
}
Пример #5
0
/********************************************************************************
 * TvCtrlPointStart
 *
 * Description: 
 *		Call this function to initialize the UPnP library and start the TV Control
 *		Point.  This function creates a timer thread and provides a callback
 *		handler to process any UPnP events that are received.
 *
 * Parameters:
 *		None
 *
 * Returns:
 *		TV_SUCCESS if everything went well, else TV_ERROR
 *
 ********************************************************************************/
int
TvCtrlPointStart( print_string printFunctionPtr,
                  state_update updateFunctionPtr )
{
    ithread_t timer_thread;
    int rc;
    unsigned short port = 0;
    char *ip_address = NULL;

    SampleUtil_Initialize( printFunctionPtr );
    SampleUtil_RegisterUpdateFunction( updateFunctionPtr );

    ithread_mutex_init( &DeviceListMutex, 0 );

    SampleUtil_Print(
        "Initializing UPnP Sdk with\n"
        "\tipaddress = %s port = %u\n",
        ip_address, port );

    rc = UpnpInit( ip_address, port );
    if( UPNP_E_SUCCESS != rc ) {
        SampleUtil_Print( "WinCEStart: UpnpInit() Error: %d", rc );
        UpnpFinish();
        return TV_ERROR;
    }

    if( NULL == ip_address ) {
        ip_address = UpnpGetServerIpAddress();
    }
    if( 0 == port ) {
        port = UpnpGetServerPort();
    }

    SampleUtil_Print(
        "UPnP Initialized\n"
	"\tipaddress= %s port = %u\n",
        ip_address, port );

    SampleUtil_Print( "Registering Control Point" );
    rc = UpnpRegisterClient( TvCtrlPointCallbackEventHandler,
                             &ctrlpt_handle, &ctrlpt_handle );
    if( UPNP_E_SUCCESS != rc ) {
        SampleUtil_Print( "Error registering CP: %d", rc );
        UpnpFinish();
        return TV_ERROR;
    }

    SampleUtil_Print( "Control Point Registered" );

    TvCtrlPointRefresh();

    // start a timer thread
    ithread_create( &timer_thread, NULL, TvCtrlPointTimerLoop, NULL );

    return TV_SUCCESS;
}
Пример #6
0
int
inthand_add(const char *name, u_int irq, void (*handler)(void *), void *arg,
    int flags, void **cookiep)
{
	struct	intr_handler *ih;
	struct	ithd *ithd, *orphan;
	int	error = 0;
	int	created_ithd = 0;

	/*
	 * Work around a race where more than one CPU may be registering
	 * handlers on the same IRQ at the same time.
	 */
	ih = &intr_handlers[irq];
	mtx_lock_spin(&intr_table_lock);
	ithd = ih->ih_ithd;
	mtx_unlock_spin(&intr_table_lock);
	if (ithd == NULL) {
		error = ithread_create(&ithd, irq, 0, irq_disable,
		    irq_enable, "irq%d:", irq);
		if (error)
			return (error);

		mtx_lock_spin(&intr_table_lock);

		if (ih->ih_ithd == NULL) {
			ih->ih_ithd = ithd;
			created_ithd++;
			mtx_unlock_spin(&intr_table_lock);
		} else {
			orphan = ithd;
			ithd = ih->ih_ithd;
			mtx_unlock_spin(&intr_table_lock);
			ithread_destroy(orphan);
		}
	}

	error = ithread_add_handler(ithd, name, handler, arg,
	    ithread_priority(flags), flags, cookiep);

	if ((flags & INTR_FAST) == 0 || error) {
		intr_setup(irq, sched_ithd, ih);
		error = 0;
	}

	if (error)
		return (error);

	if (flags & INTR_FAST)
		intr_setup(irq, handler, arg);

	intr_stray_count[irq] = 0;

	return (0);
}
Пример #7
0
/*!
 * \brief Creates a worker thread, if the thread pool does not already have
 * max threads.
 *
 * \remark The ThreadPool object mutex must be locked prior to calling this
 * function.
 *
 * \internal
 *
 * \return
 *	\li \c 0 on success, < 0 on failure.
 *	\li \c EMAXTHREADS if already max threads reached.
 *	\li \c EAGAIN if system can not create thread.
 */
static int CreateWorker(
	/*! A pointer to the ThreadPool object. */
	ThreadPool *tp)
{
	ithread_t temp;
	int rc = 0;
	ithread_attr_t attr;

	/* if a new worker is the process of starting, wait until it fully starts */
	while (tp->pendingWorkerThreadStart) {
		ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
	}

	if (tp->attr.maxThreads != INFINITE_THREADS &&
	    tp->totalThreads + 1 > tp->attr.maxThreads) {
		return EMAXTHREADS;
	}
	ithread_attr_init(&attr);
	ithread_attr_setstacksize(&attr, tp->attr.stackSize);
	ithread_attr_setdetachstate(&attr, ITHREAD_CREATE_DETACHED);
	rc = ithread_create(&temp, &attr, WorkerThread, tp);
	ithread_attr_destroy(&attr);
	if (rc == 0) {
		rc = ithread_detach(temp);
		/* ithread_detach will return EINVAL if thread has been
		 successfully detached by ithread_create */
		if (rc == EINVAL)
			rc = 0;
		tp->pendingWorkerThreadStart = 1;
		/* wait until the new worker thread starts */
		while (tp->pendingWorkerThreadStart) {
			ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
		}
	}
	if (tp->stats.maxThreads < tp->totalThreads) {
		tp->stats.maxThreads = tp->totalThreads;
	}

	return rc;
}
Пример #8
0
int main(int argc, char **argv)
{
	int rc;
	ithread_t cmdloop_thread;
#ifdef WIN32
#else
	int sig;
	sigset_t sigs_to_catch;
#endif
	int code;

	rc = TvCtrlPointStart(linux_print, NULL, 0);
	if (rc != TV_SUCCESS) {
		SampleUtil_Print("Error starting UPnP TV Control Point\n");
		return rc;
	}
	/* start a command loop thread */
	code = ithread_create(&cmdloop_thread, NULL, TvCtrlPointCommandLoop, NULL);
	if (code !=  0) {
		return UPNP_E_INTERNAL_ERROR;
	}
#ifdef WIN32
	ithread_join(cmdloop_thread, NULL);
#else
	/* Catch Ctrl-C and properly shutdown */
	sigemptyset(&sigs_to_catch);
	sigaddset(&sigs_to_catch, SIGINT);
	sigwait(&sigs_to_catch, &sig);
	SampleUtil_Print("Shutting down on signal %d...\n", sig);
#endif
	rc = TvCtrlPointStop();

	return rc;
	argc = argc;
	argv = argv;
}
Пример #9
0
//////upnp init///////////////////////////////////
int init_upnp_ctl(void)
{

  ithread_t timer_thread;
  char * ip_address;
	char *desc_doc_name;
  char *web_dir_path;
  char tmp_ipadd[20] ;//"192.168.61.22";
	char tmp_namedoc[]="ctl_xml.xml";
	unsigned short port;
  int ret = UPNP_E_SUCCESS;

  //= (*cyber_tem_ip)
         char iptmp[20];
        char * ip_data;
           get_ip(iptmp);
  port=80;
  desc_doc_name=tmp_namedoc;
  web_dir_path=DEFAULT_WEB_DIR;
    //strcpy (cyber_tem_ip, tmp_ipadd);
 
  ip_address =iptmp;//tmp_ipadd;
//  creat_xml_file(iptmp);
  // ithread_mutex_init( &TVDevMutex, NULL );
  ithread_mutex_init( &DeviceListMutex, 0 );
    printf("the iptmp is =%s\n",iptmp);
        printf("zdy is ok1");     
         //printf("the tmp_ipadd=%s\n",tmp_ipadd);
/*
      if( desc_doc_name == NULL )
        desc_doc_name = tmp_namedoc;
        printf("%s\n",*desc_doc_name);
      if( web_dir_path == NULL )
        web_dir_path = DEFAULT_WEB_DIR;      
              printf("%s\n",*web_dir_path);
  */
 if((ret=UpnpInit(ip_address, port)) != UPNP_E_SUCCESS ) {
       printf( "Error with UpnpInit -- %d\n", ret );
        UpnpFinish(  );
        printf("%d\n", ret);
        return ret;
    }

   if( ip_address == NULL )
   	 {
       ip_address = UpnpGetServerIpAddress(  );
   }
   printf("ip_address is %s\n",ip_address);
   
    if( port == 0 ) {
        port = UpnpGetServerPort(  );
    }
        printf( "UPnP Initialized\n  ipaddress= %s port = %d\n",
                      ip_address, port );
       // printf("zdy is ok1");     
       
        
   printf("bigin open the snprintf\n");
   
  // snprintf( desc_doc_url, DESC_URL_SIZE, "http://%s:%d/cgi-bin/%s", ip_address,
  //            port, desc_doc_name );
  
   printf("end  the snprintf\n");   
  // printf("desc_doc_url %s",desc_doc_url);
  
  ret=1;
     if ((ret=UpnpRegisterClient( TvCtrlPointCallbackEventHandler,
                             &ctrlpt_handle, &ctrlpt_handle ))!=UPNP_E_SUCCESS)
     {
       printf( "Error registering the rootdevice : %d\n", ret );  
       UpnpFinish(  );
        return 0;  	
     	}                        
      //     
        //TvCtrlPointRemoveAll(  );
       
        printf("TvCtrlPointRemoveAll\n");
        ret=1;
        printf("the TvDeviceType=%s\n",TvDeviceType);
        
       Tvctrlpointrefresh();
       
        ithread_create( &timer_thread, NULL, TvCtrlPointTimerLoop, NULL );
         //sleep(5);
        printf("ithread_create after\n");
        
   
   
	}