blob: 720613b3fa7fc61023a17060dd2d626415d793e1 [file] [log] [blame]
Francesco Furfaric37181b2006-04-04 23:50:50 +00001/*
2 * Copyright 2006 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.felix.upnp.sample.tv;
19
20import java.util.Properties;
21
22import org.osgi.framework.BundleContext;
23import org.osgi.framework.Filter;
24import org.osgi.framework.ServiceRegistration;
25import org.osgi.service.upnp.UPnPDevice;
26import org.osgi.service.upnp.UPnPEventListener;
27import org.osgi.service.upnp.UPnPService;
28
Francesco Furfarif2a67912006-07-17 17:08:02 +000029/*
30* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
31*/
Francesco Furfaric37181b2006-04-04 23:50:50 +000032
33public class UPnPSubscriber {
34 ServiceRegistration registration = null;
35 BundleContext context;
36 UPnPEventListener listener;
37
38 public UPnPSubscriber(BundleContext context,UPnPEventListener listener){
39 this.context = context;
40 this.listener = listener;
41 }
42
43 public void subscribe(String deviceType, String serviceType){
44 String keys = "(&(" + UPnPDevice.TYPE + "="+ deviceType + ")(" + UPnPService.TYPE + "=" + serviceType + "))";
45 try {
46 Filter filter = context.createFilter(keys);
47 Properties props = new Properties();
48 props.put(UPnPEventListener.UPNP_FILTER, filter);
49 registration = context.registerService(UPnPEventListener.class.getName(), listener, props);
50 }catch (Exception ex){
51 System.out.println(ex);
52 }
53 }
54
55 public void unsubscribe(){
56 registration.unregister();
57 registration = null;
58 }
59
60
61}