How to provide system change and file system updates?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to provide system change and file system updates?

Draško
I am trying to implement the basic MediaServer:1 and experience an issue with the client system (Parrot UPnP on QNX). It looks like it is failing in subscribing to both the system change and file system update. Anyone already had something similar before?
 

My android server code is like the following:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WifiManager wifiManager = (WifiManager)this.getSystemService(WIFI_SERVICE);
        final UpnpService upnpService = new UpnpServiceImpl(new AndroidUpnpServiceConfiguration(wifiManager));

        Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                        upnpService.shutdown();
                }
        });

        // Add the bound local device to the registry
        try {
                upnpService.getRegistry().addDevice(MyMediaServer.create());
        } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }

    }


and MyMediaServer looks like:

public class MyMediaServer extends LocalDevice {

        private MyMediaServer(DeviceIdentity pIdentity, DeviceType pType, DeviceDetails pDetails, Icon pIcon,
                        LocalService[] pMyLocalServices) throws ValidationException {
                super(pIdentity, pType, pDetails, pIcon, pMyLocalServices);
        }

        static LocalDevice create() throws ValidationException, LocalServiceBindingException, IOException {

                DeviceIdentity identity = new DeviceIdentity(UDN.uniqueSystemIdentifier("Demo Media Server"));

                DeviceType type = new UDADeviceType("MediaServer", 1);

                ManufacturerDetails manufacturerDetails = new ManufacturerDetails("kodra");
                ModelDetails modelDetails = new ModelDetails("DemoMediaServer", "A demo media server.", "v1");
                DeviceDetails details = new DeviceDetails("My UPnP", manufacturerDetails, modelDetails);

                // Icon icon = new Icon("image/png", 48, 48, 8, ???);

                AnnotationLocalServiceBinder binder = new AnnotationLocalServiceBinder();
                LocalService<MyContentDirectoryService> contentDirectoryService = createContentDirectoryService(binder);
                LocalService<ConnectionManagerService> connectionManagerService = createConnectionManagerService(binder);

                LocalService[] myLocalServices = new LocalService[] { contentDirectoryService, connectionManagerService };

                return new MyMediaServer(identity, type, details, null, myLocalServices);

                /*
                 * Several services can be bound to the same device: return new LocalDevice( identity, type, details, icon, new
                 * LocalService[] {switchPowerService, myOtherService} );
                 */

        }

        // ContentDirectory
        private static LocalService<MyContentDirectoryService> createContentDirectoryService(
                        AnnotationLocalServiceBinder binder) {
                LocalService<MyContentDirectoryService> contentDirectoryService = binder.read(MyContentDirectoryService.class);
                contentDirectoryService.setManager(new DefaultServiceManager<MyContentDirectoryService>(
                                contentDirectoryService, MyContentDirectoryService.class));
                return contentDirectoryService;
        }

        // ConnectionManager
        private static LocalService<ConnectionManagerService> createConnectionManagerService(
                        AnnotationLocalServiceBinder binder) {
                LocalService<ConnectionManagerService> connectionManagerService = binder.read(ConnectionManagerService.class);

                ProtocolInfo protocolInfo1 = new ProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, "audio/mpeg",
                                "DLNA.ORG_PN=MP3;DLNA.ORG_OP=01");
                ProtocolInfo protocolInfo2 = new ProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, "video/mpeg",
                                "DLNA.ORG_PN=MPEG1;DLNA.ORG_OP=01;DLNA.ORG_CI=0");
                final ProtocolInfos sourceProtocols = new ProtocolInfos(protocolInfo1, protocolInfo2);

                connectionManagerService.setManager(new DefaultServiceManager<ConnectionManagerService>(
                                connectionManagerService, null) {
                        @Override
                        protected ConnectionManagerService createServiceInstance() throws Exception {
                                return new ConnectionManagerService(sourceProtocols, null);
                        }
                });

                return connectionManagerService;
        }

}



Reply | Threaded
Open this post in threaded view
|

Re: How to provide system change and file system updates?

Jose Luis Larraz
did you find a solution to this?
Reply | Threaded
Open this post in threaded view
|

Re: How to provide system change and file system updates?

Jose Luis Larraz
I just found this now, so i think that this is the solution that i was seeking in the AbstractContentDirectoryService class

/**
     * Call this method after making changes to your content directory.
     * <p>
     * This will notify clients that their view of the content directory is potentially
     * outdated and has to be refreshed.
     * </p>
     */
    synchronized protected void changeSystemUpdateID()
Reply | Threaded
Open this post in threaded view
|

Re: How to provide system change and file system updates?

Draško
Thanks Jose. I have found the way to trigger a change on SystemUpdateID ... the problem is that the client I need to serve has "problems" and the only way around it is to do the reconnect (shutdown/startup).