@Override public void getAgents(DeviceWrapper wrapper, IAgentUPnPListener listener) { final DeviceWrapper refDevice = wrapper; final IAgentUPnPListener callback = listener; if (_upnpService != null) { Service service = wrapper.getDevice().findService(upnpAgentService); if (service == null) { EngineContext.log() .error("Agent JS action not found for " + wrapper.getDevice().getDisplayString()); return; } Action getAgentListAction = service.getAction("GetAgentList"); if (getAgentListAction == null) { EngineContext.log().error("Agent list action not found"); return; } ActionInvocation getAgentListInvocation = new ActionInvocation(getAgentListAction); ActionCallback getAgentListCallback = new ActionCallback(getAgentListInvocation) { @Override public void success(ActionInvocation invocation) { List<AgentScript> scripts = new ArrayList<AgentScript>(); ActionArgumentValue agents = invocation.getOutput("Agents"); if (agents != null) { if (agents.getDatatype().getBuiltin() == Datatype.Builtin.STRING) { String encodedJsonArray = String.valueOf(agents.getValue()); try { JSONArray agentJsonArray = new JSONArray(encodedJsonArray); for (int idx = 0; idx < agentJsonArray.length(); idx++) { JSONObject agentObject = agentJsonArray.getJSONObject(idx); AgentScript networkScript = new AgentNetworkScript(refDevice, agentObject); scripts.add(networkScript); } } catch (JSONException e) { e.printStackTrace(); } } } callback.setAvailableAgents(refDevice, scripts); } @Override public void failure( ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { // don't callback } }; _upnpService.getControlPoint().execute(getAgentListCallback); } }
@Override public void getSourceCode(DeviceWrapper wrapper, String agentId, IAgentUPnPListener listener) { final DeviceWrapper refDevice = wrapper; final IAgentUPnPListener callback = listener; if (_upnpService != null) { Service service = wrapper.getDevice().findService(upnpAgentService); Action getAgentSourceAction = service.getAction("GetAgentSource"); ActionInvocation getAgentSourceInvocation = new ActionInvocation(getAgentSourceAction); getAgentSourceInvocation.setInput("AgentId", agentId); ActionCallback getAgentSourceCallback = new ActionCallback(getAgentSourceInvocation) { @Override public void success(ActionInvocation invocation) { AgentScript networkScript = null; ActionArgumentValue agents = invocation.getOutput("Agent"); if (agents != null) { if (agents.getDatatype().getBuiltin() == Datatype.Builtin.STRING) { String encodedJsonArray = String.valueOf(agents.getValue()); try { JSONObject agentObject = new JSONObject(encodedJsonArray); networkScript = new AgentNetworkScript(refDevice, agentObject); } catch (JSONException e) { e.printStackTrace(); } } } callback.setAgentSourceCode(refDevice, networkScript); } @Override public void failure( ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {} }; _upnpService.getControlPoint().execute(getAgentSourceCallback); } }
DeletePortMappingActionInvocation(Service service) { super(service.getAction("DeletePortMapping")); try { // This might throw an ActionException if the value is of wrong type getInput().addValue(null); // NewRemoteHost getInput().addValue(new UnsignedIntegerTwoBytes(1234)); // NewExternalPort getInput().addValue("TCP"); // NewProtocol } catch (ActionException ex) { System.err.println(ex.getMessage()); } }
AddPortMappingActionInvocation(Service service) { super(service.getAction("AddPortMapping")); try { // This might throw an ActionException if the value is of wrong type getInput().addValue(null); // NewRemoteHost getInput().addValue(new UnsignedIntegerTwoBytes(1234)); // NewExternalPort getInput().addValue("TCP"); // NewProtocol getInput().addValue(new UnsignedIntegerTwoBytes(1234)); // NewInternalPort // TODO: This may return null String localhost = NetUtilities.getNonLoopbackAddress().getHostAddress(); System.out.println("Adding port to : " + localhost); getInput().addValue(localhost); // NewInternalClient getInput().addValue(true); // NewEnabled getInput().addValue("Description"); // NewPortMappingDescription getInput().addValue(new UnsignedIntegerFourBytes(0)); // NewLeaseDuration } catch (ActionException ex) { System.err.println(ex.getMessage()); } }
/** @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used. */ public Browse( Service service, String objectID, BrowseFlag flag, String filter, long firstResult, Long maxResults, SortCriterion... orderBy) { super(new ActionInvocation(service.getAction("Browse"))); log.fine("Creating browse action for object ID: " + objectID); getActionInvocation().setInput("ObjectID", objectID); getActionInvocation().setInput("BrowseFlag", flag.toString()); getActionInvocation().setInput("Filter", filter); getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult)); getActionInvocation() .setInput( "RequestedCount", new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults)); getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy)); }