📄 upnpapi.c
字号:
* * Description: * This function performs the same operation as UpnpSubscribeAsync * but returns immediately and calls the registered callback function * when the operation is complete. * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpSubscribeAsync( IN UpnpClient_Handle Hnd, IN const char *EvtUrl_const, IN int TimeOut, IN Upnp_FunPtr Fun, IN const void *Cookie_const ){ struct Handle_Info *SInfo = NULL; struct UpnpNonblockParam *Param; char *EvtUrl = ( char * )EvtUrl_const; ThreadPoolJob job; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpSubscribeAsync \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( EvtUrl == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( TimeOut != UPNP_INFINITE && TimeOut < 1 ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); Param = (struct UpnpNonblockParam *) malloc(sizeof (struct UpnpNonblockParam)); if( Param == NULL ) { return UPNP_E_OUTOF_MEMORY; } Param->FunName = SUBSCRIBE; Param->Handle = Hnd; strcpy( Param->Url, EvtUrl ); Param->TimeOut = TimeOut; Param->Fun = Fun; Param->Cookie = ( void * )Cookie_const; TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param ); TPJobSetFreeFunction( &job, ( free_routine ) free ); TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpSubscribeAsync \n" ); return UPNP_E_SUCCESS;} /****************** End of UpnpSubscribeAsync *********************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_CLIENT_APIS/************************************************************************** * Function: UpnpSubscribe * * Parameters: * IN UpnpClient_Handle Hnd: The handle of the control point. * IN const char *PublisherUrl: The URL of the service to subscribe to. * INOUT int *TimeOut: Pointer to a variable containing the requested * subscription time. Upon return, it contains the * actual subscription time returned from the service. * OUT Upnp_SID SubsId: Pointer to a variable to receive the * subscription ID (SID). * * Description: * This function registers a control point to receive event * notifications from another device. This operation is synchronous * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpSubscribe( IN UpnpClient_Handle Hnd, IN const char *EvtUrl_const, INOUT int *TimeOut, OUT Upnp_SID SubsId ){ struct Handle_Info *SInfo = NULL; int RetVal; char *EvtUrl = ( char * )EvtUrl_const; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpSubscribe \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( EvtUrl == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( TimeOut == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); RetVal = genaSubscribe( Hnd, EvtUrl, TimeOut, SubsId ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpSubscribe \n" ); return RetVal;} /****************** End of UpnpSubscribe *********************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_CLIENT_APIS/************************************************************************** * Function: UpnpUnSubscribe * * Parameters: * IN UpnpClient_Handle Hnd: The handle of the control point. * IN Upnp_SID SubsId: The ID returned when the control point * subscribed to the service. * * Description: * This function removes the subscription of a control point from a * service previously subscribed to using UpnpSubscribe or * UpnpSubscribeAsync. This is a synchronous call. * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpUnSubscribe( IN UpnpClient_Handle Hnd, IN Upnp_SID SubsId ){ struct Handle_Info *SInfo = NULL; int RetVal; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribe \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( SubsId == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); RetVal = genaUnSubscribe( Hnd, SubsId ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpUnSubscribe \n" ); return RetVal;} /****************** End of UpnpUnSubscribe *********************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_CLIENT_APIS/************************************************************************** * Function: UpnpUnSubscribeAsync * * Parameters: * IN UpnpClient_Handle Hnd: The handle of the subscribed control point. * IN Upnp_SID SubsId: The ID returned when the control point * subscribed to the service. * IN Upnp_FunPtr Fun: Pointer to a callback function to be called * when the operation is complete. * IN const void *Cookie:Pointer to user data to pass to the * callback function when invoked. * * Description: * This function removes a subscription of a control point * from a service previously subscribed to using UpnpSubscribe or * UpnpSubscribeAsync,generating a callback when the operation is complete. * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd, IN Upnp_SID SubsId, IN Upnp_FunPtr Fun, IN const void *Cookie_const ){ ThreadPoolJob job; struct Handle_Info *SInfo = NULL; struct UpnpNonblockParam *Param; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribeAsync \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( SubsId == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); Param = ( struct UpnpNonblockParam * ) malloc( sizeof( struct UpnpNonblockParam ) ); if( Param == NULL ) return UPNP_E_OUTOF_MEMORY; Param->FunName = UNSUBSCRIBE; Param->Handle = Hnd; strcpy( Param->SubsId, SubsId ); Param->Fun = Fun; Param->Cookie = ( void * )Cookie_const; TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param ); TPJobSetFreeFunction( &job, ( free_routine ) free ); TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpUnSubscribeAsync \n" ); return UPNP_E_SUCCESS;} /****************** End of UpnpUnSubscribeAsync *********************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_CLIENT_APIS/************************************************************************** * Function: UpnpRenewSubscription * * Parameters: * IN UpnpClient_Handle Hnd: The handle of the control point that * is renewing the subscription. * INOUT int *TimeOut: Pointer to a variable containing the * requested subscription time. Upon return, * it contains the actual renewal time. * IN Upnp_SID SubsId: The ID for the subscription to renew. * * Description: * This function renews a subscription that is about to * expire. This function is synchronous. * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpRenewSubscription( IN UpnpClient_Handle Hnd, INOUT int *TimeOut, IN Upnp_SID SubsId ){ struct Handle_Info *SInfo = NULL; int RetVal; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpRenewSubscription \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( TimeOut == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); RetVal = genaRenewSubscription( Hnd, SubsId, TimeOut ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpRenewSubscription \n" ); return RetVal;} /****************** End of UpnpRenewSubscription *********************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_CLIENT_APIS/************************************************************************** * Function: UpnpRenewSubscriptionAsync * * Parameters: * IN UpnpClient_Handle Hnd: The handle of the control point that * is renewing the subscription. * IN int TimeOut: The requested subscription time. The * actual timeout value is returned when * the callback function is called. * IN Upnp_SID SubsId: The ID for the subscription to renew. * IN Upnp_FunPtr Fun: Pointer to a callback function to be * invoked when the renewal is complete. * IN const void *Cookie : Pointer to user data passed * to the callback function when invoked. * * Description: * This function renews a subscription that is about * to expire, generating a callback when the operation is complete. * * Return Values: int * UPNP_E_SUCCESS if successful else sends appropriate error. ***************************************************************************/intUpnpRenewSubscriptionAsync( IN UpnpClient_Handle Hnd, INOUT int TimeOut, IN Upnp_SID SubsId, IN Upnp_FunPtr Fun, IN const void *Cookie_const ){ ThreadPoolJob job; struct Handle_Info *SInfo = NULL; struct UpnpNonblockParam *Param; if( UpnpSdkInit != 1 ) { return UPNP_E_FINISH; } UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpRenewSubscriptionAsync \n" ); HandleReadLock(); if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { HandleUnlock(); return UPNP_E_INVALID_HANDLE; } if( TimeOut != UPNP_INFINITE && TimeOut < 1 ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( SubsId == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } if( Fun == NULL ) { HandleUnlock(); return UPNP_E_INVALID_PARAM; } HandleUnlock(); Param = ( struct UpnpNonblockParam * ) malloc( sizeof( struct UpnpNonblockParam ) ); if( Param == NULL ) { return UPNP_E_OUTOF_MEMORY; } Param->FunName = RENEW; Param->Handle = Hnd; strcpy( Param->SubsId, SubsId ); Param->Fun = Fun; Param->Cookie = ( void * )Cookie_const; Param->TimeOut = TimeOut; TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param ); TPJobSetFreeFunction( &job, ( free_routine ) free ); TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd( &gSendThreadPool, &job, NULL ); UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpRenewSubscriptionAsync \n" ); return UPNP_E_SUCCESS;} /****************** End of UpnpRenewSubscriptionAsync *******************/#endif // INCLUDE_CLIENT_APIS#ifdef INCLUDE_DEVICE_APIS/************************************************************************** * Function: UpnpNotify * * Parameters: * IN UpnpDevice_Handle: The handle to the device sending the event. * IN const char *DevID: The device ID of the subdevice of the * service generating the event. * IN const char *ServID: The unique identifier of the service * generating the event. * IN const char **VarName: Pointer to an array of variables that * have changed. * IN const cha
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -