Add a Player to a Display Unit

This example illustrates how to add a player to a display unit.

SOAP API Method Reference

To add a player to a display unit, use the following method: host_mgr_update.

Code Samples
#!/usr/bin/php
<?php
	## Add a player to a display unit
	## Modify a host 69262182 
	## 
	## Usage:  php host_mgr_update_v12 --id=playerId --domain=domainId --display_unit_id=diplayunitId 
	## Usage example :  php host_mgr_update_v12 --id=123456789 --domain=987654321 --display_unit_id=123456789 

	include "soaplib.php";
	include "cmdutil.php";

	$options = get_arguments("id!","domain!","display_unit_id!");

	$body = new stdClass();
	$body -> id = $options["id"] ; # ID of your player
	$body -> domain_id = $options["domain"] ; #ID of your domain
	$body -> display_unit_id = $options["display_unit_id"] ; #ID of your display unit
	$body -> discovery_status = 0 ;
	$body -> name = "Host_attached_to_a_du_via_sdk" ;
	$body -> volume = 75 ;
	
	$response = performSimpleOperation("host", "update", 12, $body);

	#echo json_encode($response);
?

/*
 * (c) 2002 - 2015 BroadSign International, LLC
 */

import org.apache.axis2.Constants.Configuration;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
import org.apache.axis2.transport.http.HTTPConstants;

import com.broadsign.www.wsdl_ops.BsapiStub;
import com.broadsign.www.wsdl_types.ResourceDiscoveryStatus;

class Main {

	public static void main(String[] args) throws Exception
	{
		setupKeystore();
		BsapiStub javaStub = createStub();
		
		String basicDomain = "68110168";
		String basicDisplayUnit = "125613640";
		
		ResourceDiscoveryStatus.Enum basicPlayerDiscovery = ResourceDiscoveryStatus.X_0; // this value is constant for all active players
		String basicPlayerId = "80257625";
		String basicPlayerName = "BroadSign SDK Test - Player Name";
		int basicPlayerVolume = 10;
		String basicPlayerConfig = "69146941";
		String basicPlayerFolder = "125678621";
		String basicGeolocation = "(0,0)";
		
		HostFactory hostFactory = new HostFactory(javaStub);
//		hostFactory.list(basicDomain);
		hostFactory.update(basicPlayerDiscovery, 
				               basicPlayerId, 
				               basicPlayerName, 
				               basicPlayerVolume, 
				               basicPlayerConfig, 
				               basicPlayerFolder, basicDomain,
				               basicDisplayUnit, 1, basicGeolocation);
	}


	private static BsapiStub createStub()
	{
		try {
			ConfigurationContext config = ConfigurationContextFactory.createDefaultConfigurationContext();
			TransportOutDescription transport = new TransportOutDescription("https_mutual_auth");
			CommonsHTTPTransportSender sender = new CommonsHTTPTransportSender();

			sender.init(config, transport);
			BsapiStub javaStub = new BsapiStub();
			transport.setSender(sender);
			javaStub._getServiceClient().getOptions().setProperty(Configuration.CHARACTER_SET_ENCODING, "utf-16");
			javaStub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");
			javaStub._getServiceClient().getOptions().setTransportOut(transport);
			return javaStub;
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}
		return null;
	}
	private static void setupKeystore()
	{
		// NOTE: Make sure to update the folders where your keystore files are located
		System.setProperty("javax.net.ssl.keyStoreType", "jks");
		System.setProperty("javax.net.ssl.keyStore", "YOUR_SOAP_KEYSTORE_HERE.keystore");
		System.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SOAP_KEYSTORE_PASSWORD_HERE");
		System.setProperty("javax.net.ssl.trustStoreType", "jks");
		System.setProperty("javax.net.ssl.trustStore", "YOUR_TRUSTED_KEYSTORE_HERE.keystore");
		System.setProperty("javax.net.ssl.trustStorePassword", "YOUR_TRUSTED_KEYSTORE_PASSWORD_HERE");
	}
}

/*
 * (c) 2002 - 2015 BroadSign International, LLC
 */

import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.XmlObject;

import com.broadsign.www.wsdl_ops.BsapiStub;
import com.broadsign.www.wsdl_ops.HostMgrListRequestBody;
import com.broadsign.www.wsdl_ops.HostMgrListResponseBody;
import com.broadsign.www.wsdl_ops.HostMgrUpdateRequestBody;
import com.broadsign.www.wsdl_ops.HostMgrUpdateResponseBody;
import com.broadsign.www.wsdl_ops.RequestDocument;
import com.broadsign.www.wsdl_ops.ResponseDocument;
import com.broadsign.www.wsdl_ops.WsdlRequest;
import com.broadsign.www.wsdl_ops.WsdlResponse;
import com.broadsign.www.wsdl_types.ResourceDiscoveryStatus;

public class HostFactory {

	public HostFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public List<String> list(String domainId) throws Exception
	{
		List<String> hosts = new ArrayList<String>();
		HostMgrListRequestBody hostMgrListRequestBody = HostMgrListRequestBody.Factory.newInstance();
		WsdlRequest hostWsdlRequest = WsdlRequest.Factory.newInstance();
		XmlObject hostBodies[];
		RequestDocument hostRequestDocument = RequestDocument.Factory.newInstance();
		ResponseDocument hostResponseDocument;

		hostMgrListRequestBody.setDomainId(domainId);
		hostWsdlRequest.setName("host_mgr_list");
		hostWsdlRequest.setVersion(12);
		hostWsdlRequest.setHost(hostMgrListRequestBody);
		hostRequestDocument.setRequest(hostWsdlRequest);
		hostRequestDocument.documentProperties().setEncoding("utf-16");
		System.out.println(hostRequestDocument.xmlText());
		hostResponseDocument = m_stub.host_mgr_list_v12(hostRequestDocument);
		System.out.println(hostResponseDocument.xmlText());
		WsdlResponse response = hostResponseDocument.getResponse();
		hostBodies = response.getHostArray();

		if (hostBodies.length > 0) {
			for (XmlObject hostBody : hostBodies) {
				HostMgrListResponseBody host = HostMgrListResponseBody.Factory.parse(hostBody.xmlText());

				hosts.add(host.getName());
			}
		}

		return hosts;
	}

	public boolean update(
			ResourceDiscoveryStatus.Enum discovery_status,
			String id,
			String name,
			int volume,
			// optional parameters start below
			String config_profile_bag_id,
			String container_id,
			String domain_id,
			String display_unit_id,
			int nscreens,
			String geolocation) throws Exception
	{
		HostMgrUpdateRequestBody hostMgrUpdateRequestBody = HostMgrUpdateRequestBody.Factory.newInstance();
		WsdlRequest hostWsdlRequest = WsdlRequest.Factory.newInstance();
		XmlObject hostBodies[];
		RequestDocument hostRequestDocument = RequestDocument.Factory.newInstance();
		ResponseDocument hostResponseDocument;

		hostMgrUpdateRequestBody.setDiscoveryStatus(discovery_status);
		hostMgrUpdateRequestBody.setId(id);
		hostMgrUpdateRequestBody.setName(name);
		hostMgrUpdateRequestBody.setVolume(volume);
		hostMgrUpdateRequestBody.setConfigProfileBagId(config_profile_bag_id);
		hostMgrUpdateRequestBody.setContainerId(container_id);
		hostMgrUpdateRequestBody.setDomainId(domain_id);
		hostMgrUpdateRequestBody.setDisplayUnitId(display_unit_id);
		hostMgrUpdateRequestBody.setNscreens(nscreens);
		hostMgrUpdateRequestBody.setGeolocation(geolocation);
		hostWsdlRequest.setName("host_mgr_update");
		hostWsdlRequest.setVersion(12);
		hostWsdlRequest.setHost(hostMgrUpdateRequestBody);
		hostRequestDocument.setRequest(hostWsdlRequest);
		hostRequestDocument.documentProperties().setEncoding("utf-16");
		System.out.println(hostRequestDocument.xmlText());
		hostResponseDocument = m_stub.host_mgr_update_v12(hostRequestDocument);
		System.out.println(hostResponseDocument.xmlText());
		WsdlResponse response = hostResponseDocument.getResponse();
		hostBodies = response.getHostArray();

		if (hostBodies.length > 0) {
			for (XmlObject hostBody : hostBodies) {
				HostMgrUpdateResponseBody host = HostMgrUpdateResponseBody.Factory.parse(hostBody.xmlText());
				if(host.getId() != null) { 
					return true;
				}
			}
		}
		return false;
	}

	private BsapiStub m_stub;
}