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