1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.android;
17
18 import android.app.Service;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.IBinder;
22 import org.fourthline.cling.UpnpService;
23 import org.fourthline.cling.UpnpServiceConfiguration;
24 import org.fourthline.cling.UpnpServiceImpl;
25 import org.fourthline.cling.controlpoint.ControlPoint;
26 import org.fourthline.cling.protocol.ProtocolFactory;
27 import org.fourthline.cling.registry.Registry;
28 import org.fourthline.cling.transport.Router;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class AndroidUpnpServiceImpl extends Service {
43
44 protected UpnpService upnpService;
45 protected Binder binder = new Binder();
46
47
48
49
50 @Override
51 public void onCreate() {
52 super.onCreate();
53
54 upnpService = new UpnpServiceImpl(createConfiguration()) {
55
56 @Override
57 protected Router createRouter(ProtocolFactory protocolFactory, Registry registry) {
58 return AndroidUpnpServiceImpl.this.createRouter(
59 getConfiguration(),
60 protocolFactory,
61 AndroidUpnpServiceImpl.this
62 );
63 }
64
65 @Override
66 public synchronized void shutdown() {
67
68
69 ((AndroidRouter)getRouter()).unregisterBroadcastReceiver();
70
71
72
73
74 super.shutdown(true);
75 }
76 };
77 }
78
79 protected UpnpServiceConfiguration createConfiguration() {
80 return new AndroidUpnpServiceConfiguration();
81 }
82
83 protected AndroidRouter createRouter(UpnpServiceConfiguration configuration,
84 ProtocolFactory protocolFactory,
85 Context context) {
86 return new AndroidRouter(configuration, protocolFactory, context);
87 }
88
89 @Override
90 public IBinder onBind(Intent intent) {
91 return binder;
92 }
93
94
95
96
97 @Override
98 public void onDestroy() {
99 upnpService.shutdown();
100 super.onDestroy();
101 }
102
103 protected class Binder extends android.os.Binder implements AndroidUpnpService {
104
105 public UpnpService get() {
106 return upnpService;
107 }
108
109 public UpnpServiceConfiguration getConfiguration() {
110 return upnpService.getConfiguration();
111 }
112
113 public Registry getRegistry() {
114 return upnpService.getRegistry();
115 }
116
117 public ControlPoint getControlPoint() {
118 return upnpService.getControlPoint();
119 }
120 }
121
122 }