1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.controlpoint;
17
18 import org.fourthline.cling.UpnpServiceConfiguration;
19 import org.fourthline.cling.controlpoint.event.ExecuteAction;
20 import org.fourthline.cling.controlpoint.event.Search;
21 import org.fourthline.cling.model.message.header.MXHeader;
22 import org.fourthline.cling.model.message.header.STAllHeader;
23 import org.fourthline.cling.model.message.header.UpnpHeader;
24 import org.fourthline.cling.protocol.ProtocolFactory;
25 import org.fourthline.cling.registry.Registry;
26
27 import javax.enterprise.context.ApplicationScoped;
28 import javax.enterprise.event.Observes;
29 import javax.inject.Inject;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.Future;
32 import java.util.logging.Logger;
33
34
35
36
37
38
39
40
41
42
43 @ApplicationScoped
44 public class ControlPointImpl implements ControlPoint {
45
46 private static Logger log = Logger.getLogger(ControlPointImpl.class.getName());
47
48 protected UpnpServiceConfiguration configuration;
49 protected ProtocolFactory protocolFactory;
50 protected Registry registry;
51
52 protected ControlPointImpl() {
53 }
54
55 @Inject
56 public ControlPointImpl(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, Registry registry) {
57 log.fine("Creating ControlPoint: " + getClass().getName());
58
59 this.configuration = configuration;
60 this.protocolFactory = protocolFactory;
61 this.registry = registry;
62 }
63
64 public UpnpServiceConfiguration getConfiguration() {
65 return configuration;
66 }
67
68 public ProtocolFactory getProtocolFactory() {
69 return protocolFactory;
70 }
71
72 public Registry getRegistry() {
73 return registry;
74 }
75
76 public void search(@Observes Search search) {
77 search(search.getSearchType(), search.getMxSeconds());
78 }
79
80 public void search() {
81 search(new STAllHeader(), MXHeader.DEFAULT_VALUE);
82 }
83
84 public void search(UpnpHeader searchType) {
85 search(searchType, MXHeader.DEFAULT_VALUE);
86 }
87
88 public void search(int mxSeconds) {
89 search(new STAllHeader(), mxSeconds);
90 }
91
92 public void search(UpnpHeader searchType, int mxSeconds) {
93 log.fine("Sending asynchronous search for: " + searchType.getString());
94 getConfiguration().getAsyncProtocolExecutor().execute(
95 getProtocolFactory().createSendingSearch(searchType, mxSeconds)
96 );
97 }
98
99 public void execute(ExecuteAction executeAction) {
100 execute(executeAction.getCallback());
101 }
102
103 public Future execute(ActionCallback callback) {
104 log.fine("Invoking action in background: " + callback);
105 callback.setControlPoint(this);
106 ExecutorService executor = getConfiguration().getSyncProtocolExecutorService();
107 return executor.submit(callback);
108 }
109
110 public void execute(SubscriptionCallback callback) {
111 log.fine("Invoking subscription in background: " + callback);
112 callback.setControlPoint(this);
113 getConfiguration().getSyncProtocolExecutorService().execute(callback);
114 }
115 }