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
void GPAC_MediaController::OnMRStateVariablesChanged(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars )
{
	u32 count;
	u32 i;
	s32 render_idx = -1;

	count = gf_list_count(m_MediaRenderers);
	for (i=0; i<count; i++) {
		GPAC_MediaRendererItem *mr = (GPAC_MediaRendererItem *) gf_list_get(m_MediaRenderers, i);
		if ( mr->m_device.AsPointer() == service->GetDevice() ) {
			render_idx = i;
			break;
		}
	}
	if (render_idx < 0) return;
	
	count = vars->GetItemCount();
	for (i=0; i<count; i++) {
		PLT_StateVariable *svar;
		vars->Get(i, svar);
		if (svar->GetName() == NPT_String("AbsoluteTimePosition")) {
			u32 h, m, s;
			if (sscanf((char *) svar->GetValue(), "%d:%d:%d", &h, &m, &s)==3) {
				Double time = h*3600 + m*60 + s;
				this->m_pUPnP->onTimeChanged(render_idx, time);
			}
		}
		else if (svar->GetName() == NPT_String("CurrentTrackDuration")) {
			u32 h, m, s;
			if (sscanf((char *) svar->GetValue(), "%d:%d:%d", &h, &m, &s)==3) {
				Double time = h*3600 + m*60 + s;
				this->m_pUPnP->onDurationChanged(render_idx, time);
			}
		}

	}
}
Beispiel #3
0
void 
GPAC_MediaController::OnMSStateVariablesChanged(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars)
{
	GPAC_MediaServerItem *ms = NULL;
	gf_mx_p(m_ControlPointLock);

	u32 i, count;
	count = gf_list_count(m_MediaServers);
	for (i=0; i<count; i++) {
		GPAC_MediaServerItem *ms = (GPAC_MediaServerItem *) gf_list_get(m_MediaServers, i);
		if (ms->m_UUID==service->GetDevice()->GetUUID()) {
			break;
		}
		ms = NULL;
	}
	
	if (!ms) {
		gf_mx_v(m_ControlPointLock);
		return;
	}

    PLT_StateVariable* var = PLT_StateVariable::Find(*vars, "ContainerUpdateIDs");
    if (var) {
        // variable found, parse value
        NPT_String value = var->GetValue();
        NPT_String item_id, update_id;
        int index;

        while (value.GetLength()) {
            // look for container id
            index = value.Find(',');
            if (index < 0) break;
            item_id = value.Left(index);
            value = value.SubString(index+1);

            // look for update id
            if (value.GetLength()) {
                index = value.Find(',');
                update_id = (index<0)?value:value.Left(index);
                value = (index<0)?"":value.SubString(index+1);

				m_pUPnP->ContainerChanged(ms->m_device, item_id, update_id);
            }       
        }
    }        
	gf_mx_v(m_ControlPointLock);
}
Beispiel #4
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::OnMSStateVariablesChanged
+---------------------------------------------------------------------*/
void 
PLT_SyncMediaBrowser::OnMSStateVariablesChanged(PLT_Service*                  service, 
                                                NPT_List<PLT_StateVariable*>* vars)
{
    NPT_AutoLock lock(m_MediaServers);
    
    PLT_DeviceDataReference device;
    const NPT_List<PLT_DeviceMapEntry*>::Iterator it = 
        m_MediaServers.GetEntries().Find(PLT_DeviceMapFinderByUUID(service->GetDevice()->GetUUID()));
    if (!it) return; // device with this service has gone away

    device = (*it)->GetValue();
    PLT_StateVariable* var = PLT_StateVariable::Find(*vars, "ContainerUpdateIDs");
    if (var) {
        // variable found, parse value
        NPT_String value = var->GetValue();
        NPT_String item_id, update_id;
        int index;

        while (value.GetLength()) {
            // look for container id
            index = value.Find(',');
            if (index < 0) break;
            item_id = value.Left(index);
            value = value.SubString(index+1);

            // look for update id
            if (value.GetLength()) {
                index = value.Find(',');
                update_id = (index<0)?value:value.Left(index);
                value = (index<0)?"":value.SubString(index+1);

                // clear cache for that device
                if (m_UseCache) m_Cache.Clear(device->GetUUID(), item_id);

                // notify listener
                if (m_ContainerListener) m_ContainerListener->OnContainerChanged(device, item_id, update_id);
            }       
        }
    }        
}
Beispiel #5
0
/*----------------------------------------------------------------------
|   PLT_MediaController::OnEventNotify
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnEventNotify(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars)
{
    if (m_Listener) {
        // parse LastChange var into smaller vars
        PLT_StateVariable* lastChangeVar = NULL;
        if (NPT_SUCCEEDED(NPT_ContainerFind(*vars, PLT_ListStateVariableNameFinder("LastChange"), lastChangeVar))) {
            vars->Remove(lastChangeVar);
            PLT_Service* var_service = lastChangeVar->GetService();
            NPT_String text = lastChangeVar->GetValue();
            
            NPT_XmlNode* xml = NULL;
            NPT_XmlParser parser;
            if (NPT_FAILED(parser.Parse(text, xml)) || !xml || !xml->AsElementNode()) {
                delete xml;
                return NPT_FAILURE;
            }

            NPT_XmlElementNode* node = xml->AsElementNode();
            if (!node->GetTag().Compare("Event", true)) {
                // look for the instance with attribute id = 0
                NPT_XmlElementNode* instance = NULL;
                for (NPT_Cardinal i=0; i<node->GetChildren().GetItemCount(); i++) {
                    NPT_XmlElementNode* child;
                    if (NPT_FAILED(PLT_XmlHelper::GetChild(node, child, i)))
                        continue;

                    if (!child->GetTag().Compare("InstanceID", true)) {
                        // extract the "val" attribute value
                        NPT_String value;
                        if (NPT_SUCCEEDED(PLT_XmlHelper::GetAttribute(child, "val", value)) &&
                            !value.Compare("0")) {
                            instance = child;
                            break;
                        }
                    }
                }

                // did we find an instance with id = 0 ?
                if (instance != NULL) {
                    // all the children of the Instance node are state variables
                    for (NPT_Cardinal j=0; j<instance->GetChildren().GetItemCount(); j++) {
                        NPT_XmlElementNode* var_node;
                        if (NPT_FAILED(PLT_XmlHelper::GetChild(instance, var_node, j)))
                            continue;

                        // look for the state variable in this service
                        const NPT_String* value = var_node->GetAttribute("val");
                        PLT_StateVariable* var = var_service->FindStateVariable(var_node->GetTag());
                        if (value != NULL && var != NULL) {
                            // get the value and set the state variable
                            // if it succeeded, add it to the list of vars we'll event
                            if (NPT_SUCCEEDED(var->SetValue(*value, false))) {
                                vars->Add(var);
                                NPT_LOG_FINE_2("PLT_MediaController received var change for (%s): %s", (const char*)var->GetName(), (const char*)var->GetValue());
                            }
                        }
                    }
                }
            }
            delete xml;
        }

        if (vars->GetItemCount()) {
            m_Listener->OnMRStateVariablesChanged(service, vars);
        }
    }
    return NPT_SUCCESS;
}