UPnP programming

UPnP programming

Cyberlink Java

Cyberlink Programmer's Guide

Echo

Echo device description


<?xml version="1.0" ?> 
<root xmlns="urn:schemas-upnp-org:device-1-0">
	<specVersion>
		<major>1</major> 
		<minor>0</minor> 
	</specVersion>
	<device>
		<deviceType>urn:schemas-upnp-org:device:echo:1</deviceType> 
		<friendlyName>Echo device</friendlyName> 
		<manufacturer>Jan Newmarch</manufacturer> 
		<manufacturerURL>http://jan.newmarch.name</manufacturerURL> 
		<modelDescription>Jan's Simple Echo Device</modelDescription> 
		<modelName>Echo</modelName> 
		<modelNumber>1.0</modelNumber> 
		<modelURL>http://jan.newmarch.name</modelURL> 
		<serialNumber>1234567890</serialNumber> 
		<UDN>uuid:jan_echo_server_1</UDN> 
		<UPC>123456789012</UPC> 
		<iconList>
			<icon>
				<mimetype>image/gif</mimetype> 
				<width>48</width> 
				<height>32</height> 
				<depth>8</depth> 
				<url>/description/icon.gif</url> 
			</icon>
		</iconList>
		<serviceList>
			<service>
				<serviceType>urn:schemas-upnp-org:service:echo:1</serviceType> 
				<serviceId>urn:schemas-upnp-org:serviceId:echo:1</serviceId> 
				<SCPDURL>/service_description.xml</SCPDURL> 
				<controlURL>/service/timer/control</controlURL> 
				<eventSubURL>/service/timer/eventSub</eventSubURL> 
			</service>
		</serviceList>
		<presentationURL>/presentation</presentationURL> 
	</device>
</root>

Echo service description


<?xml version="1.0"?>
<scpd xmlns="urn:schemas-upnp-org:service-1-0" >
    <specVersion>
	<major>1</major>
	<minor>0</minor>
    </specVersion>
    <actionList>
	<action>
	    <name>Echo</name>
	    <argumentList>
		<argument>
		    <name>InText</name>
  		    <relatedStateVariable>Text</relatedStateVariable>
		    <direction>in</direction>
		</argument>
		<argument>
		    <name>ReturnText</name>
		    <relatedStateVariable>Text</relatedStateVariable>
		    <direction>out</direction>
		</argument>
	    </argumentList>
	</action>
    </actionList>
    <serviceStateTable>
	<stateVariable sendEvents="no">
	    <name>Text</name>
	    <dataType>string</dataType>
	</stateVariable>
    </serviceStateTable>
</scpd>

Echo device



Echo client



Ant file for echo

A build.xml is


<project name="UPnP demos" default="usage" basedir=".">

    <!-- CONFIGURABLE STUFF HERE -->
    <!-- where this directory is -->
    <property name="top" value="/home/httpd/html/internetdevices/upnp/java/echo"/>

    <property name="upnp_lib" value="${top}/lib/clink132a.jar"/>
    <property name="xerces_lib" value="${top}/lib/xercesImpl.jar"/>
    <property name="xml_lib" value="${top}/lib/xml-apis.jar"/>

    <!-- END CONFIGURABLE STUFF -->

    <!-- Directories -->

  <!-- Show the usage options to the user -->
  <target name="usage" >
    <echo message=""/>
    <echo message=""/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message="available targets are:"/>
    <echo message=""/>
    <echo message=" compile"/>
    <echo message=" rundevice"/>
    <echo message=" runclient"/>
    <echo message=" clean"/>
    <echo message=" usage"/>
    <echo message=""/>
    <echo message="See comments inside the build.xml file for more details."/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message=""/>
  </target>

  <target name="all" depends="init,compile"/> 

    <!-- CLEAN -->
    <target name="clean">
 	<!-- Delete our the ${build}, and ${deploy} directory trees -->
	<delete dir="classes"/>
    </target>


    <target name="init">
	<!-- Create the build directory structure used by compile N deploy -->
    </target>

    <target name="compile">
	<mkdir dir="classes"/>
	<javac destdir="classes" srcdir="src" 
	       classpath="${upnp_lib}"
               target="1.1"/>
    </target>

    <target name="runclient" depends="compile">
	<java
            classpath="${upnp_lib}:${xerces_lib}:${xml_lib}:classes"
	    classname="controlPoint.Client"/>
    </target>

    <target name="rundevice" depends="compile">
	<exec executable="java">
            <env key="CLASSPATH" 
                 path="${upnp_lib}:${xerces_lib}:${xml_lib}:classes"/>
	    <arg line="device.EchoDevice"/>
	</exec>
    </target>
</project>

Compile and run

Flashing clocks

Timer service

Java classes for timer service

Code is available from here

Running the example

All the source code is available from here . This includes an ant build.xml file. You can use this to build/run the examples by


ant compileclock
ant runtickerclock
ant runcomputerclock
If you don't want to do it this way, you can run any Java compiler/runtime or IDE with the classpath set to include the files

clink123a.jar
xercesImpl.jar
xml-apis.jar
These files are in the zip file with the source code

Time

A convenience class to handle ISO 8601 time format

Timer

Interface for different implementations of timers, matches the methods defined for the timer service

Computer Timer

Implementation of timer that gets its time from the computer clock using the Calendar class

Ticker Timer

Another implementation that runs a "ticker" in a thread to update the time. This timer is invalid until something else sets its time

Clock device

TickerClock

This creates a clock device, sets a ticker timer in it and starts the frame

ComputerClock

This creates a clock device, sets a computer timer in it and starts the frame

Clock Frame

A JFrame to display the clock

Clock Pane

And a JPane to display the clock


Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Wed May 26 10:45:31 EST 2004
Copyright ©Jan Newmarch