Commit 5f93fb42 authored by Brendan Long's avatar Brendan Long

Create a server which gets discovered and sends an empty UI list.

parent 17897b88
export PKG_CONFIG_PATH
LD_FLAGS += \$(pkg-config --libs gupnp-1.0 gssdp-1.0 gobject-2.0 libxml-2.0 libsoup-2.4 gee-1.0 json-glib-1.0) -g
VALA_FLAGS += --pkg=gupnp-1.0 --pkg=gee-1.0 --pkg=json-glib-1.0 --pkg=gio-2.0 -X -w -g
LD_FLAGS += \$(pkg-config --libs gupnp-1.0 gssdp-1.0 gobject-2.0 libxml-2.0 gee-1.0) -g
VALA_FLAGS += --pkg=gupnp-1.0 --pkg=gee-1.0 --pkg=gio-2.0 -X -w -g
.gitignore
......
<?xml version="1.0" encoding="UTF-8"?>
<scpd xmlns="urn:schemas-upnp-org:service-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<actionList>
<action>
<name>GetCompatibleUIs</name>
<argumentList>
<argument>
<name>InputDeviceProfile</name>
<direction>in</direction>
<relatedStateVariable>A_ARG_TYPE_DeviceProfile</relatedStateVariable>
</argument>
<argument>
<name>UIFilter</name>
<direction>in</direction>
<relatedStateVariable>A_ARG_TYPE_String</relatedStateVariable>
</argument>
<argument>
<name>UIListing</name>
<direction>out</direction>
<relatedStateVariable>A_ARG_TYPE_CompatibleUIs</relatedStateVariable>
</argument>
</argumentList>
</action>
<action>
<name>SetUILifetime</name>
<argumentList>
<argument>
<name>UI</name>
<direction>in</direction>
<relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable>
</argument>
<argument>
<name>Lifetime</name>
<direction>in</direction>
<relatedStateVariable>A_ARG_TYPE_Int</relatedStateVariable>
</argument>
</argumentList>
</action>
</actionList>
<serviceStateTable>
<stateVariable sendEvents="yes">
<name>UIListingUpdate</name>
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
<name>A_ARG_TYPE_DeviceProfile</name>
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
<name>A_ARG_TYPE_URI</name>
<dataType>uri</dataType>
</stateVariable>
<stateVariable sendEvents="no">
<name>A_ARG_TYPE_CompatibleUIs</name>
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
<name>A_ARG_TYPE_String</name>
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
<name>A_ARG_TYPE_Int</name>
<dataType>int</dataType>
</stateVariable>
</serviceStateTable>
</scpd>
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<modelName>RemoteUI Server</modelName>
<modelNumber>GAR-1.2</modelNumber>
<UPC>111111111111</UPC>
<deviceType>urn:schemas-upnp-org:device:RemoteUIServerDevice:1</deviceType>
<friendlyName>Gars RemoteUI Server</friendlyName>
<manufacturer>GAR</manufacturer>
<modelURL>http://www.cablelabs.com</modelURL>
<manufacturerURL>http://www.cablelabs.com</manufacturerURL>
<UDN>uuid:10BE8B1E-E265-4e34-A50B-FF715F6084A9</UDN>
<serialNumber>GAR-000.1.3</serialNumber>
<modelDescription>Gars RemoteUI Server Device</modelDescription>
<iconList>
<icon>
<mimetype>image/jpeg</mimetype>
<width>48</width>
<height>32</height>
<depth>8</depth>
<url>/icon</url>
</icon>
</iconList>
<serviceList>
<service>
<serviceId>urn:upnp-org:serviceId:RemoteUIServer</serviceId>
<controlURL>/RemoteUIServer1/Control</controlURL>
<eventSubURL>/RemoveUIServer1/Event</eventSubURL>
<SCPDURL>/RemoteUIServer1.xml</SCPDURL>
<serviceType>urn:schemas-upnp-org:service:RemoteUIServer:1</serviceType>
</service>
</serviceList>
</device>
</root>
errordomain RUIError {
BAD_CONFIG
}
class RemoteUIServer {
static const string REMOTE_UI_SERVICE_TYPE = "urn:schemas-upnp-org:service:RemoteUIServer:1";
string root_device_xml;
string service_directory;
GUPnP.Context context;
GUPnP.RootDevice root_device;
public RemoteUIServer(string root_device_xml, string service_directory) {
this.root_device_xml = root_device_xml;
this.service_directory = service_directory;
}
public void start() throws Error {
context = new GUPnP.Context(null, null, 0);
root_device = new GUPnP.RootDevice(context, root_device_xml,
service_directory);
root_device.set_available(true);
stdout.printf("Running UPnP service on http://%s:%u/%s\n", context.host_ip, context.port, root_device.description_path);
var service = (GUPnP.Service)root_device.get_service(REMOTE_UI_SERVICE_TYPE);
if (service == null) {
throw new RUIError.BAD_CONFIG(
"Unable to get %s.".printf(REMOTE_UI_SERVICE_TYPE));
}
service.action_invoked["GetCompatibleUIs"].connect(on_get_compatible_uis);
MainLoop loop = new MainLoop();
loop.run();
}
void on_get_compatible_uis(GUPnP.ServiceAction action) {
action.set_value("UIListing", "<uilist></uilist>");
action.return();
}
}
static string? root_device_xml = null;
static string? service_directory = null;
static bool debug = false;
static const OptionEntry[] options = {
{ "root-device-xml", 0, 0, OptionArg.FILENAME, ref root_device_xml,
"The root device XML file.", "[file]" },
{ "service-directory", 0, 0, OptionArg.FILENAME, ref service_directory,
"The directory with service XML files.", "[file]" },
{ "debug", 'd', 0, OptionArg.NONE, ref debug,
"Print debug messages to the console", null },
{ null }
};
static int main(string[] args) {
try {
var opt_context = new OptionContext("UPnP RemoteUIServer");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (ref args);
if (root_device_xml == null) {
throw new OptionError.BAD_VALUE("Missing --root-device-xml");
}
if (service_directory == null) {
throw new OptionError.BAD_VALUE("Missing --service-directory");
}
} catch (OptionError e) {
stderr.printf ("%s\n", e.message);
stderr.printf ("Run '%s --help' to see a full list of available command line options.\n",
args[0]);
return 2;
}
try {
RemoteUIServer server = new RemoteUIServer(root_device_xml,
service_directory);
server.start();
return 0;
} catch (Error e) {
stderr.printf("Error running RemoteUIServer: %s\n", e.message);
return 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment