Beispiel #1
0
/*----------------------------------------------------------------------
|   PLT_LightSampleDevice::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_LightSampleDevice::OnAction(PLT_ActionReference& action, NPT_SocketInfo* /* info */)
{
    /* parse the action name */
    NPT_String name = action->GetActionDesc()->GetName();
    if (name.Compare("SetTarget") == 0) {
        NPT_String value;
        action->GetArgumentValue("newTargetValue", value);

        PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");
        if (NPT_FAILED(variable->SetValue(value))) {
            action->SetError(402, "Invalid Args");
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    } else if (name.Compare("GetStatus") == 0) {
        PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");
        if (variable) {
            action->SetArgumentValue("ResultStatus", variable->GetValue());
            return NPT_SUCCESS;
        }
    }
    
    action->SetError(501, "Action Failed");
    return NPT_FAILURE;
}
Beispiel #2
0
NPT_Result
GPAC_GenericDevice::OnAction(PLT_ActionReference&          action,
                             const PLT_HttpRequestContext& context)
{
	NPT_COMPILER_UNUSED(context);

#ifdef GPAC_HAS_SPIDERMONKEY
	gf_mx_p(m_pMutex);
#endif
	PLT_ActionDesc &act_desc = action->GetActionDesc();
	NPT_String name = act_desc.GetName();
#ifdef GPAC_HAS_SPIDERMONKEY
	assert(!m_pSema);
#endif
	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Action %s called (thread %d)\n", (char *) name, gf_th_id() ));

#ifdef GPAC_HAS_SPIDERMONKEY
	if (JSVAL_IS_NULL(act_proc)) {
		gf_mx_v(m_pMutex);
		return NPT_SUCCESS;
	}

	jsval argv[2];

	m_pUPnP->LockJavascript(GF_TRUE);

	JSObject *js_action = JS_NewObject(m_pUPnP->m_pJSCtx, &m_pUPnP->upnpDeviceClass._class, 0, 0);
	argv[0] = OBJECT_TO_JSVAL(js_action);
	SMJS_SET_PRIVATE(m_pUPnP->m_pJSCtx, js_action, this);

	act_ref = action;

	JS_DefineProperty(m_pUPnP->m_pJSCtx, js_action, "Name", STRING_TO_JSVAL( JS_NewStringCopyZ(m_pUPnP->m_pJSCtx, name) ), 0, 0, JSPROP_READONLY | JSPROP_PERMANENT);
	GPAC_Service *service = (GPAC_Service *) act_desc.GetService();
	JS_DefineProperty(m_pUPnP->m_pJSCtx, js_action, "Service", service->m_pObj ? OBJECT_TO_JSVAL( service->m_pObj) : JSVAL_NULL, 0, 0, JSPROP_READONLY | JSPROP_PERMANENT);
	JS_DefineFunction(m_pUPnP->m_pJSCtx, js_action, "GetArgument", upnp_action_get_argument, 1, 0);
	JS_DefineFunction(m_pUPnP->m_pJSCtx, js_action, "SendReply", upnp_action_send_reply, 1, 0);

	/*create a semaphore*/
	m_pSema = gf_sema_new(1, 0);

	jsval rval;
	JS_CallFunctionValue(m_pUPnP->m_pJSCtx, obj, act_proc, 1, argv, &rval);
	SMJS_SET_PRIVATE(m_pUPnP->m_pJSCtx, js_action, NULL);
	m_pUPnP->LockJavascript(GF_FALSE);

	if (JSVAL_IS_INT(rval) && (JSVAL_TO_INT(rval) != 0)) {
		action->SetError(JSVAL_TO_INT(rval), "Action Failed");
	}
	/*wait on the semaphore*/
	if (!gf_sema_wait_for(m_pSema, 10000)) {
		GF_LOG(GF_LOG_WARNING, GF_LOG_NETWORK, ("[UPnP] Reply processing to action %s timeout - sending incomplete reply)\n", (char *) name));
	}
	gf_sema_del(m_pSema);
	m_pSema = NULL;

	gf_mx_v(m_pMutex);
#endif
	return NPT_SUCCESS;
}
Beispiel #3
0
/*----------------------------------------------------------------------
|   PLT_MediaBrowser::OnActionResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnActionResponse(NPT_Result           res, 
                                   PLT_ActionReference& action, 
                                   void*                userdata)
{
    NPT_String actionName = action->GetActionDesc().GetName();

    // look for device in our list first
    PLT_DeviceDataReference device;
    NPT_String uuid = action->GetActionDesc().GetService()->GetDevice()->GetUUID();
    if (NPT_FAILED(FindServer(uuid, device))) res = NPT_FAILURE;

    // Browse action response
    if (actionName.Compare("Browse", true) == 0) {
        return OnBrowseResponse(res, device, action, userdata);
    } else if (actionName.Compare("Search", true) == 0) {
        return OnSearchResponse(res, device, action, userdata);
    }

    return NPT_SUCCESS;
}
Beispiel #4
0
/*----------------------------------------------------------------------
|   PLT_MediaBrowser::OnActionResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata)
{
    PLT_DeviceDataReference device;

    {
        NPT_AutoLock lock(m_MediaServers);
        NPT_String uuid = action->GetActionDesc()->GetService()->GetDevice()->GetUUID();
        if (NPT_FAILED(NPT_ContainerFind(m_MediaServers, PLT_DeviceDataFinder(uuid), device))) {
            NPT_LOG_WARNING_1("Device (%s) not found in our list of servers", (const char*)uuid);
            return NPT_FAILURE;
        }
    }

    NPT_String actionName = action->GetActionDesc()->GetName();

    // Browse action response
    if (actionName.Compare("Browse", true) == 0) {
        return OnBrowseResponse(res, device, action, userdata);
    }

    return NPT_SUCCESS;
}
Beispiel #5
0
/*----------------------------------------------------------------------
|       PLT_MediaConnect::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnAction(PLT_ActionReference&          action, 
                           const NPT_HttpRequestContext& context)
{
      PLT_MediaConnectInfo* mc_info = NULL;

//    /* get MAC address from IP */
//    if (info != NULL) {
//        NPT_String ip = info->remote_address.GetIpAddress().ToString();
//        NPT_String MAC;
//        GetMACFromIP(ip, MAC);
//
//        if (MAC.GetLength()) {
//            NPT_Result res = m_MediaConnectDeviceInfoMap.Get(MAC, mc_info);
//            if (NPT_FAILED(res)) {
//                m_MediaConnectDeviceInfoMap.Put(MAC, PLT_MediaConnectInfo());
//                m_MediaConnectDeviceInfoMap.Get(MAC, mc_info);
//
//                // automatically validate for now
//                Authorize(mc_info, true);
//            }
//        }
//    }
//
//    /* verify device is allowed first */
//    if (mc_info == NULL || !mc_info->m_Authorized) {
//        action->SetError(801, "Access Denied");
//        return NPT_SUCCESS;
//    }

    /* parse the action name */
    NPT_String name = action->GetActionDesc()->GetName();

    /* handle X_MS_MediaReceiverRegistrar actions here */
    if (name.Compare("IsAuthorized") == 0) {
        return OnIsAuthorized(action, mc_info);
    }
    if (name.Compare("RegisterDevice") == 0) {
        return OnRegisterDevice(action, mc_info);
    }
    if (name.Compare("IsValidated") == 0) {
        return OnIsValidated(action, mc_info);
    }  

    return PLT_FileMediaServer::OnAction(action, context);
}
Beispiel #6
0
/*----------------------------------------------------------------------
|   PLT_MediaServer::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaServer::OnAction(PLT_ActionReference&          action, 
                          const PLT_HttpRequestContext& context)
{
    /* parse the action name */
    NPT_String name = action->GetActionDesc().GetName();
                   
    // ContentDirectory
    if (name.Compare("Browse", true) == 0) {
        return OnBrowse(action, context);
    }
    if (name.Compare("Search", true) == 0) {
        return OnSearch(action, context);
    }
    if (name.Compare("UpdateObject", true) == 0) {
        return OnUpdate(action, context);
    }
    if (name.Compare("GetSystemUpdateID", true) == 0) {
        return OnGetSystemUpdateID(action, context);
    }
    if (name.Compare("GetSortCapabilities", true) == 0) {
        return OnGetSortCapabilities(action, context);
    }  
    if (name.Compare("GetSearchCapabilities", true) == 0) {
        return OnGetSearchCapabilities(action, context);
    }  

    // ConnectionMananger
    if (name.Compare("GetCurrentConnectionIDs", true) == 0) {
        return OnGetCurrentConnectionIDs(action, context);
    }
    if (name.Compare("GetProtocolInfo", true) == 0) {
        return OnGetProtocolInfo(action, context);
    }    
    if (name.Compare("GetCurrentConnectionInfo", true) == 0) {
        return OnGetCurrentConnectionInfo(action, context);
    }

    action->SetError(401,"No Such Action.");
    return NPT_SUCCESS;
}
Beispiel #7
0
/*----------------------------------------------------------------------
|       PLT_MediaConnect::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnAction(PLT_ActionReference&          action, 
                           
                           const PLT_HttpRequestContext& context)
{
    /* parse the action name */
    NPT_String name = action->GetActionDesc().GetName();

    /* handle X_MS_MediaReceiverRegistrar actions here */
    if (name.Compare("IsAuthorized") == 0) {
        return OnIsAuthorized(action);
    }
    if (name.Compare("RegisterDevice") == 0) {
        return OnRegisterDevice(action);
    }
    if (name.Compare("IsValidated") == 0) {
        return OnIsValidated(action);
    }  

    return PLT_MediaServer::OnAction(action, context);
}
/*----------------------------------------------------------------------
|   PLT_MediaRenderer::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaRenderer::OnAction(PLT_ActionReference& action, NPT_SocketInfo* info /* = NULL */)
{
    NPT_COMPILER_UNUSED(info);

    /* parse the action name */
    NPT_String name = action->GetActionDesc()->GetName();

    /* Is it a ConnectionManager Service Action ? */
    if (name.Compare("GetCurrentConnectionIDs", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetProtocolInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }    
    if (name.Compare("GetCurrentConnectionInfo", true) == 0) {
        return OnGetCurrentConnectionInfo(action);
    }  

    /* Is it a AVTransport Service Action ? */

    // since all actions take an instance ID and we only support 1 instance
    // verify that the Instance ID is 0 and return an error here now if not
    NPT_String serviceType = action->GetActionDesc()->GetService()->GetServiceType();
    if (serviceType.Compare("urn:schemas-upnp-org:service:AVTransport:1", true) == 0) {
        if (NPT_FAILED(action->VerifyArgumentValue("InstanceID", "0"))) {
            action->SetError(802,"Not valid InstanceID.");
            return NPT_FAILURE;
        }
    }

    if (name.Compare("GetCurrentTransportActions", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetDeviceCapabilities", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetMediaInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetPositionInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetTransportInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetTransportSettings", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("Next", true) == 0) {
        return OnNext(action);
    }
    if (name.Compare("Pause", true) == 0) {
        return OnPause(action);
    }
    if (name.Compare("Play", true) == 0) {
        return OnPlay(action);
    }
    if (name.Compare("Previous", true) == 0) {
        return OnPrevious(action);
    }
    if (name.Compare("Seek", true) == 0) {
        return OnSeek(action);
    }
    if (name.Compare("Stop", true) == 0) {
        return OnStop(action);
    }
    if (name.Compare("SetAVTransportURI", true) == 0) {
        return OnSetAVTransportURI(action);
    }
    if (name.Compare("SetPlayMode", true) == 0) {
        return OnSetPlayMode(action);
    }

    action->SetError(401,"No Such Action.");
    return NPT_FAILURE;
}
Beispiel #9
0
/*----------------------------------------------------------------------
|   PLT_MediaRenderer::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaRenderer::OnAction(PLT_ActionReference&          action,
                            const PLT_HttpRequestContext& context)
{
    NPT_COMPILER_UNUSED(context);

    /* parse the action name */
    NPT_String name = action->GetActionDesc().GetName();

    // since all actions take an instance ID and we only support 1 instance
    // verify that the Instance ID is 0 and return an error here now if not
    NPT_String serviceType = action->GetActionDesc().GetService()->GetServiceType();
    if (serviceType.Compare("urn:schemas-upnp-org:service:AVTransport:1", true) == 0) {
        if (NPT_FAILED(action->VerifyArgumentValue("InstanceID", "0"))) {
            action->SetError(718, "Not valid InstanceID");
            return NPT_FAILURE;
        }
    }
    serviceType = action->GetActionDesc().GetService()->GetServiceType();
    if (serviceType.Compare("urn:schemas-upnp-org:service:RenderingControl:1", true) == 0) {
        if (NPT_FAILED(action->VerifyArgumentValue("InstanceID", "0"))) {
            action->SetError(702, "Not valid InstanceID");
            return NPT_FAILURE;
        }
    }

    /* Is it a ConnectionManager Service Action ? */
    if (name.Compare("GetCurrentConnectionInfo", true) == 0) {
        return OnGetCurrentConnectionInfo(action);
    }

    /* Is it a AVTransport Service Action ? */
    if (name.Compare("Next", true) == 0) {
        return OnNext(action);
    }
    if (name.Compare("Pause", true) == 0) {
        return OnPause(action);
    }
    if (name.Compare("Play", true) == 0) {
        return OnPlay(action);
    }
    if (name.Compare("Previous", true) == 0) {
        return OnPrevious(action);
    }
    if (name.Compare("Seek", true) == 0) {
        return OnSeek(action);
    }
    if (name.Compare("Stop", true) == 0) {
        return OnStop(action);
    }
    if (name.Compare("SetAVTransportURI", true) == 0) {
        return OnSetAVTransportURI(action);
    }
    if (name.Compare("SetNextAVTransportURI", true) == 0) {
        return OnSetNextAVTransportURI(action);
    }
    if (name.Compare("SetPlayMode", true) == 0) {
        return OnSetPlayMode(action);
    }

    /* Is it a RendererControl Service Action ? */
    if (name.Compare("SetVolume", true) == 0) {
        return OnSetVolume(action);
    }
    if (name.Compare("SetVolumeDB", true) == 0) {
        return OnSetVolumeDB(action);
    }
    if (name.Compare("GetVolumeDBRange", true) == 0) {
        return OnGetVolumeDBRange(action);

    }
    if (name.Compare("SetMute", true) == 0) {
        return OnSetMute(action);
    }

    // other actions rely on state variables
    NPT_CHECK_LABEL_WARNING(action->SetArgumentsOutFromStateVariable(), failure);
    return NPT_SUCCESS;

failure:
    action->SetError(401,"No Such Action.");
    return NPT_FAILURE;
}
Beispiel #10
0
NPT_Result
GPAC_MediaRenderer::OnAction(PLT_ActionReference&          action,
                            const PLT_HttpRequestContext& context)
{
    NPT_COMPILER_UNUSED(context);

    /* parse the action name */
    NPT_String name = action->GetActionDesc().GetName();

	m_ip_src = context.GetRemoteAddress().GetIpAddress().ToString();

	/* Is it a ConnectionManager Service Action ? */
    if (name.Compare("GetCurrentConnectionIDs", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetProtocolInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetCurrentConnectionInfo", true) == 0) {
        return OnGetCurrentConnectionInfo(action);
    }
    if (name.Compare("StopForMigration", true) == 0) {
		NPT_String res = m_pUPnP->OnMigrate();
        m_pMigrationService->SetStateVariable("MigrationStatus", "OK");
        m_pMigrationService->SetStateVariable("MigrationMetaData", res);

		if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }

    /* Is it a AVTransport Service Action ? */

    // since all actions take an instance ID and we only support 1 instance
    // verify that the Instance ID is 0 and return an error here now if not
    NPT_String serviceType = action->GetActionDesc().GetService()->GetServiceType();
    if (serviceType.Compare("urn:schemas-upnp-org:service:AVTransport:1", true) == 0) {
        if (NPT_FAILED(action->VerifyArgumentValue("InstanceID", "0"))) {
            action->SetError(802,"Not valid InstanceID.");
            return NPT_FAILURE;
        }
    }

    if (name.Compare("GetCurrentTransportActions", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetDeviceCapabilities", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetMediaInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetPositionInfo", true) == 0) {
		if (m_pUPnP->m_pTerm->root_scene) {
			char szVal[100];

			m_pAVService->SetStateVariable("CurrentTrack", "0");
			format_time_string(szVal, m_Duration);
			m_pAVService->SetStateVariable("CurrentTrackDuration", szVal);

			m_pAVService->SetStateVariable("CurrentTrackMetadata", "");
			m_pAVService->SetStateVariable("CurrentTrackURI", "");
			format_time_string(szVal, m_Time);
			m_pAVService->SetStateVariable("RelativeTimePosition", szVal);
			m_pAVService->SetStateVariable("AbsoluteTimePosition", szVal);
			m_pAVService->SetStateVariable("RelativeCounterPosition", "2147483647"); // means NOT_IMPLEMENTED
			m_pAVService->SetStateVariable("AbsoluteCounterPosition", "2147483647"); // means NOT_IMPLEMENTED
		} else {
			if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
				return NPT_FAILURE;
			}
		}
        return NPT_SUCCESS;
    }
    if (name.Compare("GetTransportInfo", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("GetTransportSettings", true) == 0) {
        if (NPT_FAILED(action->SetArgumentsOutFromStateVariable())) {
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    }
    if (name.Compare("Next", true) == 0) {
        return OnNext(action);
    }
    if (name.Compare("Pause", true) == 0) {
        return OnPause(action);
    }
    if (name.Compare("Play", true) == 0) {
        return OnPlay(action);
    }
    if (name.Compare("Previous", true) == 0) {
        return OnPrevious(action);
    }
    if (name.Compare("Seek", true) == 0) {
        return OnSeek(action);
    }
    if (name.Compare("Stop", true) == 0) {
        return OnStop(action);
    }
    if (name.Compare("SetAVTransportURI", true) == 0) {
        return OnSetAVTransportURI(action);
    }
    if (name.Compare("SetPlayMode", true) == 0) {
        return OnSetPlayMode(action);
    }

    /* Is it a RendererControl Service Action ? */
    if (serviceType.Compare("urn:schemas-upnp-org:service:RenderingControl:1", true) == 0) {
        /* we only support master channel */
        if (NPT_FAILED(action->VerifyArgumentValue("Channel", "Master"))) {
            action->SetError(402,"Invalid Args.");
            return NPT_FAILURE;
        }
    }

    if (name.Compare("GetVolume", true) == 0) {
        NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable());
        return NPT_SUCCESS;
    }

    if (name.Compare("GetMute", true) == 0) {
        NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable());
        return NPT_SUCCESS;
    }

    if (name.Compare("SetVolume", true) == 0) {
          return OnSetVolume(action);
    }

    if (name.Compare("SetMute", true) == 0) {
          return OnSetMute(action);
    }

    action->SetError(401,"No Such Action.");
    return NPT_FAILURE;
}
Beispiel #11
0
NPT_Result GPAC_GenericController::OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata)
{
#ifdef GPAC_HAS_SPIDERMONKEY
	u32 i, count;
	GPAC_DeviceItem *item = NULL;
	GPAC_ServiceItem *serv = NULL;
	GPAC_ActionArgListener *argl, *act_l;
	PLT_Service* service = action->GetActionDesc().GetService();
	NPT_String uuid;
	GPAC_ActionUDTA *act_udta = (GPAC_ActionUDTA *)userdata;

	/*this is NOT an actionResponse to an action triggered on a generic device*/
	if (act_udta && act_udta->m_Reserved) act_udta = NULL;

	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Receive %s Response - error code %d\n", (char *) action->GetActionDesc().GetName(), res));

	gf_mx_p(m_ControlPointLock);

	/*get our device*/
	uuid = service->GetDevice()->GetUUID();
	count = gf_list_count(m_Devices);
	for (i=0; i<count; i++) {
		item = (GPAC_DeviceItem *) gf_list_get(m_Devices, i);
		if (item->m_UUID == uuid ) {
			break;
		}
		item = NULL;
	}
	gf_mx_v(m_ControlPointLock);

	if (!item) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[UPnP] Receive %s Response on unknown device (uuid %s)\n", (char *) action->GetActionDesc().GetName(), (char *) uuid));
		goto exit;
	}
	/*get our service*/
	count = gf_list_count(item->m_Services);
	for (i=0; i<count; i++) {
		serv = (GPAC_ServiceItem *)gf_list_get(item->m_Services, i);
		if (serv->m_service == service) break;
	}
	if (!serv) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[UPnP] Receive %s Response on unknown service %s\n", (char *) action->GetActionDesc().GetName(), (char *) service->GetServiceType()));
		goto exit;
	}

	/*locate our listeners*/
	act_l = NULL;
	i=0;
	while ((argl = (GPAC_ActionArgListener *)gf_list_enum(serv->m_ArgListeners, &i))) {
		NPT_String value;
		GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] checking argument %s\n", (char *) argl->action->GetName() ));
		if (argl->action->GetName() != action->GetActionDesc().GetName() ) continue;

		/*global action listener*/
		if (argl->arg==NULL) {
			act_l = argl;
			continue;
		}
		/*if error don't trigger listeners*/
		if (res != NPT_SUCCESS) {
			GF_LOG(GF_LOG_WARNING, GF_LOG_NETWORK, ("[UPnP] Receive %s Response: error on remote device %d\n", (char *) action->GetActionDesc().GetName(), res));
			continue;
		}
		/*action arg listener*/
		if (action->GetArgumentValue(argl->arg->GetName(), value) == NPT_SUCCESS) {
			jsval argv[1], rval;

			GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling handler for response %s argument %s\n", (char *) action->GetActionDesc().GetName(), (char *) argl->arg->GetName() ));
			m_pUPnP->LockJavascript(GF_TRUE);
			argv[0] = STRING_TO_JSVAL( JS_NewStringCopyZ(serv->js_ctx, value) );
			JS_CallFunctionValue(serv->js_ctx, serv->obj, argl->on_event, 1, argv, &rval);
			m_pUPnP->LockJavascript(GF_FALSE);
		} else {
			GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[UPnP] %s Response: couldn't get argument %s value\n", (char *) action->GetActionDesc().GetName(), (char *) argl->arg->GetName() ));
		}
	}

	if (act_l) {
		jsval rval;
		m_pUPnP->LockJavascript(GF_TRUE);
		if (act_l->is_script) {
			JSObject *act_obj;
			jsval argv[2];

			GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling handler for response %s\n", (char *) action->GetActionDesc().GetName()));

			act_obj = JS_NewObject(serv->js_ctx, &item->m_pUPnP->upnpDeviceClass._class, 0, item->obj);
			SMJS_SET_PRIVATE(serv->js_ctx, act_obj, (void *)action.AsPointer() );
			JS_DefineFunction(serv->js_ctx, act_obj, "GetArgumentValue", upnp_action_get_argument_value, 1, 0);
			JS_DefineFunction(serv->js_ctx, act_obj, "GetErrorCode", upnp_action_get_error_code, 1, 0);
			JS_DefineFunction(serv->js_ctx, act_obj, "GetError", upnp_action_get_error, 1, 0);

			gf_js_add_root(serv->js_ctx, &act_obj, GF_JSGC_OBJECT);
			argv[0] = OBJECT_TO_JSVAL(act_obj);
			if (act_udta) {
				argv[1] = act_udta->udta;
				JS_CallFunctionValue(serv->js_ctx, serv->obj, act_l->on_event, 2, argv, &rval);
			} else {
				JS_CallFunctionValue(serv->js_ctx, serv->obj, act_l->on_event, 1, argv, &rval);
			}
			gf_js_remove_root(serv->js_ctx, &act_obj, GF_JSGC_OBJECT);
		}
		/*if error don't trigger listeners*/
		else if (res == NPT_SUCCESS) {
			GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling handler for response %s\n", (char *) action->GetActionDesc().GetName()));
			JS_CallFunctionValue(serv->js_ctx, serv->obj, act_l->on_event, 0, 0, &rval);
		}
		else {
			GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[UPnP] response %s has error %d\n", (char *) action->GetActionDesc().GetName(), res ));
		}
		m_pUPnP->LockJavascript(GF_FALSE);
	}
	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Done processing response %s\n", (char *) action->GetActionDesc().GetName()));

exit:
	if (act_udta) {
		gf_js_remove_root(serv->js_ctx, &act_udta->udta, GF_JSGC_VAL);
		delete act_udta;
	}

	return NPT_SUCCESS;
#else
	return NPT_SUCCESS;
#endif
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnActionResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnActionResponse(NPT_Result           res, 
                                      PLT_ActionReference& action, 
                                      void*                userdata)
{
    if (m_Delegate == NULL) return NPT_SUCCESS;

    PLT_DeviceDataReference device;
    NPT_String uuid = action->GetActionDesc().GetService()->GetDevice()->GetUUID();
           
    /* extract action name */
    NPT_String actionName = action->GetActionDesc().GetName();

    /* AVTransport response ? */
    if (actionName.Compare("GetCurrentTransportActions", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetCurrentTransportActionsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetDeviceCapabilities", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetDeviceCapabilitiesResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetMediaInfo", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetMediaInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetPositionInfo", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetPositionInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetTransportInfo", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetTransportInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetTransportSettings", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetTransportSettingsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("Next", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnNextResult(res, device, userdata);
    }
    else if (actionName.Compare("Pause", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnPauseResult(res, device, userdata);
    }
    else if (actionName.Compare("Play", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnPlayResult(res, device, userdata);
    }
    else if (actionName.Compare("Previous", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnPreviousResult(res, device, userdata);
    }
    else if (actionName.Compare("Seek", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnSeekResult(res, device, userdata);
    }
    else if (actionName.Compare("SetAVTransportURI", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnSetAVTransportURIResult(res, device, userdata);
    }
    else if (actionName.Compare("SetPlayMode", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnSetPlayModeResult(res, device, userdata);
    }
    else if (actionName.Compare("Stop", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnStopResult(res, device, userdata);
    }
    else if (actionName.Compare("GetCurrentConnectionIDs", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetCurrentConnectionIDsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetCurrentConnectionInfo", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetCurrentConnectionInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetProtocolInfo", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetProtocolInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("SetMute", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnSetMuteResult(res, device, userdata);
    }
    else if (actionName.Compare("GetMute", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetMuteResponse(res, device, action, userdata);
    }
	else if (actionName.Compare("SetVolume", true) == 0) { 
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        m_Delegate->OnSetVolumeResult(res, device, userdata);
    }
    else if (actionName.Compare("GetVolume", true) == 0) {
        if (NPT_FAILED(FindRenderer(uuid, device))) res = NPT_FAILURE;
        return OnGetVolumeResponse(res, device, action, userdata);
    }

    return NPT_SUCCESS;
}
Beispiel #13
0
/*----------------------------------------------------------------------
|   PLT_MediaController::OnActionResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata)
{
    if (m_Listener == NULL) {
        return NPT_SUCCESS;
    }

    /* make sure device is a renderer we've previously found */
    PLT_DeviceDataReference device;
    NPT_String uuid = action->GetActionDesc()->GetService()->GetDevice()->GetUUID();
    if (NPT_FAILED(NPT_ContainerFind(m_MediaRenderers, PLT_DeviceDataFinder(uuid), device))) {
        NPT_LOG_FINE_1("Device (%s) not found in our list of renderers", (const char*)uuid);
        res = NPT_FAILURE;
    }
       
    /* extract action name */
    NPT_String actionName = action->GetActionDesc()->GetName();

    /* AVTransport response ? */
    if (actionName.Compare("GetCurrentTransportActions", true) == 0) {
        return OnGetCurrentTransportActionsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetDeviceCapabilities", true) == 0) {
        return OnGetDeviceCapabilitiesResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetMediaInfo", true) == 0) {
        return OnGetMediaInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetPositionInfo", true) == 0) {
        return OnGetPositionInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetTransportInfo", true) == 0) {
        return OnGetTransportInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetTransportSettings", true) == 0) {
        return OnGetTransportSettingsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("Next", true) == 0) {
        m_Listener->OnNextResult(res, device, userdata);
    }
    else if (actionName.Compare("Pause", true) == 0) {
        m_Listener->OnPauseResult(res, device, userdata);
    }
    else if (actionName.Compare("Play", true) == 0) {
        m_Listener->OnPlayResult(res, device, userdata);
    }
    else if (actionName.Compare("Previous", true) == 0) {
        m_Listener->OnPreviousResult(res, device, userdata);
    }
    else if (actionName.Compare("Seek", true) == 0) {
        m_Listener->OnSeekResult(res, device, userdata);
    }
    else if (actionName.Compare("SetAVTransportURI", true) == 0) {
        m_Listener->OnSetAVTransportURIResult(res, device, userdata);
    }
    else if (actionName.Compare("SetPlayMode", true) == 0) {
        m_Listener->OnSetPlayModeResult(res, device, userdata);
    }
    else if (actionName.Compare("Stop", true) == 0) {
        m_Listener->OnStopResult(res, device, userdata);
    }
    else if (actionName.Compare("GetCurrentConnectionIDs", true) == 0) {
        return OnGetCurrentConnectionIDsResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetCurrentConnectionInfo", true) == 0) {
        return OnGetCurrentConnectionInfoResponse(res, device, action, userdata);
    }
    else if (actionName.Compare("GetProtocolInfo", true) == 0) {
        return OnGetProtocolInfoResponse(res, device, action, userdata);
    }

    return NPT_SUCCESS;
}