org.fourthline.cling.model.meta.Action Java Examples

The following examples show how to use org.fourthline.cling.model.meta.Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
private ActionArgumentValue<RemoteService>[] getArguments(final Action<RemoteService> action) {
    @SuppressWarnings("unchecked")
    final ActionArgument<RemoteService>[] actionArguments = action.getArguments();
    final Map<String, Object> argumentValues = getArgumentValues();
    final List<ActionArgumentValue<RemoteService>> actionArgumentValues = new ArrayList<>(actionArguments.length);

    for (final ActionArgument<RemoteService> actionArgument : actionArguments) {
        if (actionArgument.getDirection() == Direction.IN) {
            final Object value = argumentValues.get(actionArgument.getName());
            logger.trace("Action {}: add arg value for {}: {} (expected datatype: {})", action.getName(),
                    actionArgument, value, actionArgument.getDatatype().getDisplayString());
            actionArgumentValues.add(new ActionArgumentValue<>(actionArgument, value));
        }
    }
    @SuppressWarnings("unchecked")
    final ActionArgumentValue<RemoteService>[] array = actionArgumentValues
            .toArray(new ActionArgumentValue[0]);
    return array;
}
 
Example #2
Source File: AnnotationActionBinder.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public Action appendAction(Map<Action, ActionExecutor> actions) throws LocalServiceBindingException {

        String name;
        if (getAnnotation().name().length() != 0) {
            name = getAnnotation().name();
        } else {
            name = AnnotationLocalServiceBinder.toUpnpActionName(getMethod().getName());
        }

        log.fine("Creating action and executor: " + name);

        List<ActionArgument> inputArguments = createInputArguments();
        Map<ActionArgument<LocalService>, StateVariableAccessor> outputArguments = createOutputArguments();

        inputArguments.addAll(outputArguments.keySet());
        ActionArgument<LocalService>[] actionArguments =
                inputArguments.toArray(new ActionArgument[inputArguments.size()]);

        Action action = new Action(name, actionArguments);
        ActionExecutor executor = createExecutor(outputArguments);

        actions.put(action, executor);
        return action;
    }
 
Example #3
Source File: AnnotationLocalServiceBinder.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #4
Source File: AnnotationLocalServiceBinder.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected Map<Action, ActionExecutor> readActions(Class<?> clazz,
                                                  Map<StateVariable, StateVariableAccessor> stateVariables,
                                                  Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<Action, ActionExecutor> map = new HashMap();

    for (Method method : Reflections.getMethods(clazz, UpnpAction.class)) {
        AnnotationActionBinder actionBinder =
                new AnnotationActionBinder(method, stateVariables, stringConvertibleTypes);
        Action action = actionBinder.appendAction(map);
        if(isActionExcluded(action)) {
        	map.remove(action);
        }
    }

    return map;
}
 
Example #5
Source File: AbstractActionExecutor.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the output arguments after an action execution using accessors.
 *
 * @param action The action of which the output arguments are read.
 * @param instance The instance on which the accessors will be invoked.
 * @return <code>null</code> if the action has no output arguments, a single instance if it has one, an
 *         <code>Object[]</code> otherwise.
 * @throws Exception
 */
protected Object readOutputArgumentValues(Action<LocalService> action, Object instance) throws Exception {
    Object[] results = new Object[action.getOutputArguments().length];
    log.fine("Attempting to retrieve output argument values using accessor: " + results.length);

    int i = 0;
    for (ActionArgument outputArgument : action.getOutputArguments()) {
        log.finer("Calling acccessor method for: " + outputArgument);

        StateVariableAccessor accessor = getOutputArgumentAccessors().get(outputArgument);
        if (accessor != null) {
            log.fine("Calling accessor to read output argument value: " + accessor);
            results[i++] = accessor.read(instance);
        } else {
            throw new IllegalStateException("No accessor bound for: " + outputArgument);
        }
    }

    if (results.length == 1) {
        return results[0];
    }
    return results.length > 0 ? results : null;
}
 
Example #6
Source File: AbstractActionExecutor.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads the output arguments after an action execution using accessors.
 *
 * @param action The action of which the output arguments are read.
 * @param instance The instance on which the accessors will be invoked.
 * @return <code>null</code> if the action has no output arguments, a single instance if it has one, an
 *         <code>Object[]</code> otherwise.
 * @throws Exception
 */
protected Object readOutputArgumentValues(Action<LocalService> action, Object instance) throws Exception {
    Object[] results = new Object[action.getOutputArguments().length];
    log.fine("Attempting to retrieve output argument values using accessor: " + results.length);

    int i = 0;
    for (ActionArgument outputArgument : action.getOutputArguments()) {
        log.finer("Calling acccessor method for: " + outputArgument);

        StateVariableAccessor accessor = getOutputArgumentAccessors().get(outputArgument);
        if (accessor != null) {
            log.fine("Calling accessor to read output argument value: " + accessor);
            results[i++] = accessor.read(instance);
        } else {
            throw new IllegalStateException("No accessor bound for: " + outputArgument);
        }
    }

    if (results.length == 1) {
        return results[0];
    }
    return results.length > 0 ? results : null;
}
 
Example #7
Source File: AnnotationLocalServiceBinder.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected Map<Action, ActionExecutor> readActions(Class<?> clazz,
                                                  Map<StateVariable, StateVariableAccessor> stateVariables,
                                                  Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<Action, ActionExecutor> map = new HashMap();

    for (Method method : Reflections.getMethods(clazz, UpnpAction.class)) {
        AnnotationActionBinder actionBinder =
                new AnnotationActionBinder(method, stateVariables, stringConvertibleTypes);
        Action action = actionBinder.appendAction(map);
        if(isActionExcluded(action)) {
        	map.remove(action);
        }
    }

    return map;
}
 
Example #8
Source File: AnnotationLocalServiceBinder.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #9
Source File: AnnotationActionBinder.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public Action appendAction(Map<Action, ActionExecutor> actions) throws LocalServiceBindingException {

        String name;
        if (getAnnotation().name().length() != 0) {
            name = getAnnotation().name();
        } else {
            name = AnnotationLocalServiceBinder.toUpnpActionName(getMethod().getName());
        }

        log.fine("Creating action and executor: " + name);

        List<ActionArgument> inputArguments = createInputArguments();
        Map<ActionArgument<LocalService>, StateVariableAccessor> outputArguments = createOutputArguments();

        inputArguments.addAll(outputArguments.keySet());
        ActionArgument<LocalService>[] actionArguments =
                inputArguments.toArray(new ActionArgument[inputArguments.size()]);

        Action action = new Action(name, actionArguments);
        ActionExecutor executor = createExecutor(outputArguments);

        actions.put(action, executor);
        return action;
    }
 
Example #10
Source File: ActionInvocation.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ActionArgumentValue<S>[] output,
                        ClientInfo clientInfo) {
    if (action == null) {
        throw new IllegalArgumentException("Action can not be null");
    }
    this.action = action;

    setInput(input);
    setOutput(output);

    this.clientInfo = clientInfo;
}
 
Example #11
Source File: MutableService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public Action[] createActions() {
    Action[] array = new Action[actions.size()];
    int i = 0;
    for (MutableAction action : actions) {
        array[i++] = action.build();
    }
    return array;
}
 
Example #12
Source File: UDA10ServiceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) {

        Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList);

        for (Action action : serviceModel.getActions()) {
            if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME))
                generateAction(action, descriptor, actionListElement);
        }
    }
 
Example #13
Source File: UDA10ServiceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
private void generateAction(Action action, Document descriptor, Element actionListElement) {

        Element actionElement = appendNewElement(descriptor, actionListElement, ELEMENT.action);

        appendNewElementIfNotNull(descriptor, actionElement, ELEMENT.name, action.getName());

        if (action.hasArguments()) {
            Element argumentListElement = appendNewElement(descriptor, actionElement, ELEMENT.argumentList);
            for (ActionArgument actionArgument : action.getArguments()) {
                generateActionArgument(actionArgument, descriptor, argumentListElement);
            }
        }
    }
 
Example #14
Source File: OutgoingActionResponseMessage.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public OutgoingActionResponseMessage(UpnpResponse.Status status, Action action) {
    super(new UpnpResponse(status));

    if (action != null) {
        if (action instanceof QueryStateVariableAction) {
            this.actionNamespace = Constants.NS_UPNP_CONTROL_10;
        } else {
            this.actionNamespace = action.getService().getServiceType().toString();
        }
    }

    addHeaders();
}
 
Example #15
Source File: RemoteActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public RemoteActionInvocation(Action action,
                              ActionArgumentValue[] input,
                              ActionArgumentValue[] output,
                              RemoteClientInfo remoteClientInfo) {
    super(action, input, output, null);
    this.remoteClientInfo = remoteClientInfo;
}
 
Example #16
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ActionArgumentValue<S>[] output,
                        ClientInfo clientInfo) {
    if (action == null) {
        throw new IllegalArgumentException("Action can not be null");
    }
    this.action = action;

    setInput(input);
    setOutput(output);

    this.clientInfo = clientInfo;
}
 
Example #17
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionInvocation<RemoteService> getActionInvocation() {
    final Action<RemoteService> action = service.getAction(actionName);
    if (action == null) {
        throw new ClingRouterException("No action found for name '" + actionName + "'. Available actions: "
                + Arrays.toString(service.getActions()));
    }
    final ActionArgumentValue<RemoteService>[] argumentArray = getArguments(action);
    return new ActionInvocation<>(action, argumentArray);
}
 
Example #18
Source File: MutableService.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public Action[] createActions() {
    Action[] array = new Action[actions.size()];
    int i = 0;
    for (MutableAction action : actions) {
        array[i++] = action.build();
    }
    return array;
}
 
Example #19
Source File: UDA10ServiceDescriptorBinderImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) {

        Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList);

        for (Action action : serviceModel.getActions()) {
            if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME))
                generateAction(action, descriptor, actionListElement);
        }
    }
 
Example #20
Source File: UDA10ServiceDescriptorBinderImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
private void generateAction(Action action, Document descriptor, Element actionListElement) {

        Element actionElement = appendNewElement(descriptor, actionListElement, ELEMENT.action);

        appendNewElementIfNotNull(descriptor, actionElement, ELEMENT.name, action.getName());

        if (action.hasArguments()) {
            Element argumentListElement = appendNewElement(descriptor, actionElement, ELEMENT.argumentList);
            for (ActionArgument actionArgument : action.getArguments()) {
                generateActionArgument(actionArgument, descriptor, argumentListElement);
            }
        }
    }
 
Example #21
Source File: RemoteActionInvocation.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public RemoteActionInvocation(Action action,
                              ActionArgumentValue[] input,
                              ActionArgumentValue[] output,
                              RemoteClientInfo remoteClientInfo) {
    super(action, input, output, null);
    this.remoteClientInfo = remoteClientInfo;
}
 
Example #22
Source File: OutgoingActionResponseMessage.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public OutgoingActionResponseMessage(UpnpResponse.Status status, Action action) {
    super(new UpnpResponse(status));

    if (action != null) {
        if (action instanceof QueryStateVariableAction) {
            this.actionNamespace = Constants.NS_UPNP_CONTROL_10;
        } else {
            this.actionNamespace = action.getService().getServiceType().toString();
        }
    }

    addHeaders();
}
 
Example #23
Source File: OutgoingActionResponseMessage.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public OutgoingActionResponseMessage(Action action) {
    this(UpnpResponse.Status.OK, action);
}
 
Example #24
Source File: DLNAController.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void create(final boolean playing, final int seconds) {
	downloadService.setPlayerState(PlayerState.PREPARING);

	callback = new SubscriptionCallback(getTransportService(), 600) {
		@Override
		protected void failed(GENASubscription genaSubscription, UpnpResponse upnpResponse, Exception e, String msg) {
			Log.w(TAG, "Register subscription callback failed: " + msg, e);
		}

		@Override
		protected void established(GENASubscription genaSubscription) {
			Action seekAction = genaSubscription.getService().getAction("Seek");
			if(seekAction != null) {
				StateVariable seekMode = genaSubscription.getService().getStateVariable("A_ARG_TYPE_SeekMode");
				for(String allowedValue: seekMode.getTypeDetails().getAllowedValues()) {
					if("REL_TIME".equals(allowedValue)) {
						supportsSeek = true;
					}
				}
			}
			Action setupNextAction = genaSubscription.getService().getAction("SetNextAVTransportURI");
			if(setupNextAction != null) {
				supportsSetupNext = true;
			}

			startSong(downloadService.getCurrentPlaying(), playing, seconds);
			downloadService.postDelayed(searchDLNA, SEARCH_UPDATE_INTERVAL_SECONDS);
		}

		@Override
		protected void ended(GENASubscription genaSubscription, CancelReason cancelReason, UpnpResponse upnpResponse) {
			Log.i(TAG, "Ended subscription");
			if(cancelReason != null) {
				Log.i(TAG, "Cancel Reason: " + cancelReason.toString());
			}
			if(upnpResponse != null) {
				Log.i(TAG, "Reponse Message: " + upnpResponse.getStatusMessage());
				Log.i(TAG, "Response Details: " + upnpResponse.getResponseDetails());
			}
		}

		@Override
		protected void eventReceived(GENASubscription genaSubscription) {
			Map<String, StateVariableValue> m = genaSubscription.getCurrentValues();
			try {
				String lastChangeText = m.get("LastChange").toString();
				lastChangeText = lastChangeText.replace(",X_DLNA_SeekTime","").replace(",X_DLNA_SeekByte", "");
				LastChange lastChange = new LastChange(new AVTransportLastChangeParser(), lastChangeText);

				if (lastChange.getEventedValue(0, AVTransportVariable.TransportState.class) == null) {
					return;
				}

				switch (lastChange.getEventedValue(0, AVTransportVariable.TransportState.class).getValue()) {
					case PLAYING:
						downloadService.setPlayerState(PlayerState.STARTED);
						break;
					case PAUSED_PLAYBACK:
						downloadService.setPlayerState(PlayerState.PAUSED);
						break;
					case STOPPED:
						boolean failed = false;
						for(StateVariableValue val: m.values()) {
							if(val.toString().indexOf("TransportStatus val=\"ERROR_OCCURRED\"") != -1) {
								Log.w(TAG, "Failed to load with event: " + val.toString());
								failed = true;
							}
						}

						if(failed) {
							failedLoad();
						} else if(downloadService.getPlayerState() == PlayerState.STARTED) {
							// Played until the end
							downloadService.onSongCompleted();
						} else {
							downloadService.setPlayerState(PlayerState.STOPPED);
						}
						break;
					case TRANSITIONING:
						downloadService.setPlayerState(PlayerState.PREPARING);
						break;
					case NO_MEDIA_PRESENT:
						downloadService.setPlayerState(PlayerState.IDLE);
						break;
					default:
				}
			}
			catch (Exception e) {
				Log.w(TAG, "Failed to parse UPNP event", e);
			}
		}

		@Override
		protected void eventsMissed(GENASubscription genaSubscription, int i) {
			Log.w(TAG, "Event missed: " + i);
		}
	};
	controlPoint.execute(callback);
}
 
Example #25
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public Action<S> getAction() {
    return action;
}
 
Example #26
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ActionArgumentValue<S>[] output) {
    this(action, input, output, null);
}
 
Example #27
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input,
                        ClientInfo clientInfo) {
    this(action, input, null, clientInfo);
}
 
Example #28
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ActionArgumentValue<S>[] input) {
    this(action, input, null, null);
}
 
Example #29
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionInvocation(Action<S> action,
                        ClientInfo clientInfo) {
    this(action, null, null, clientInfo);
}
 
Example #30
Source File: ActionInvocation.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ActionInvocation(Action<S> action) {
    this(action, null, null, null);
}