/*! * \brief This is a thread function to send the renewal just before the * subscription times out. */ static void GenaAutoRenewSubscription( /*! [in] Thread data(upnp_timeout *) needed to send the renewal. */ IN void *input) { upnp_timeout *event = (upnp_timeout *) input; struct Upnp_Event_Subscribe *sub_struct = (struct Upnp_Event_Subscribe *)event->Event; void *cookie; Upnp_FunPtr callback_fun; struct Handle_Info *handle_info; int send_callback = 0; int eventType = 0; int timeout = 0; int errCode = 0; UpnpString *tmpSID = UpnpString_new(); if (AUTO_RENEW_TIME == 0) { UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUB EXPIRED"); sub_struct->ErrCode = UPNP_E_SUCCESS; send_callback = 1; eventType = UPNP_EVENT_SUBSCRIPTION_EXPIRED; } else { UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "GENA AUTO RENEW"); timeout = sub_struct->TimeOut; UpnpString_set_String(tmpSID, sub_struct->Sid); errCode = genaRenewSubscription( event->handle, tmpSID, &timeout); sub_struct->ErrCode = errCode; sub_struct->TimeOut = timeout; if (errCode != UPNP_E_SUCCESS && errCode != GENA_E_BAD_SID && errCode != GENA_E_BAD_HANDLE) { send_callback = 1; eventType = UPNP_EVENT_AUTORENEWAL_FAILED; } } if (send_callback) { HandleReadLock(); if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) { HandleUnlock(); free_upnp_timeout(event); goto end_function; } UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID"); /* make callback */ callback_fun = handle_info->Callback; cookie = handle_info->Cookie; HandleUnlock(); callback_fun(eventType, event->Event, cookie); } free_upnp_timeout(event); end_function: UpnpString_delete(tmpSID); return; }
/************************************************************************ * Function : GenaAutoRenewSubscription * * Parameters: * IN void *input: Thread data(upnp_timeout *) needed to send the renewal * * Description: * This is a thread function to send the renewal just before the * subscription times out. * * Returns: VOID * ***************************************************************************/ static void GenaAutoRenewSubscription( IN void *input ) { upnp_timeout *event = ( upnp_timeout * ) input; void *cookie; Upnp_FunPtr callback_fun; struct Handle_Info *handle_info; struct Upnp_Event_Subscribe *sub_struct = ( struct Upnp_Event_Subscribe * ) event->Event; int send_callback = 0; int eventType = 0; if( AUTO_RENEW_TIME == 0 ) { DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUB EXPIRED" ) ); sub_struct->ErrCode = UPNP_E_SUCCESS; send_callback = 1; eventType = UPNP_EVENT_SUBSCRIPTION_EXPIRED; } else { DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA AUTO RENEW" ) ); if( ( ( sub_struct->ErrCode = genaRenewSubscription( event->handle, sub_struct-> Sid, &sub_struct-> TimeOut ) ) != UPNP_E_SUCCESS ) && ( sub_struct->ErrCode != GENA_E_BAD_SID ) && ( sub_struct->ErrCode != GENA_E_BAD_HANDLE ) ) { send_callback = 1; eventType = UPNP_EVENT_AUTORENEWAL_FAILED; } } if( send_callback ) { HandleLock( ); if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) { HandleUnlock( ); free_upnp_timeout( event ); return; } DBGONLY( UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID" ) ); callback_fun = handle_info->Callback; cookie = handle_info->Cookie; HandleUnlock( ); //make callback callback_fun( eventType, event->Event, cookie ); } free_upnp_timeout( event ); }