Francesco Furfari | c37181b | 2006-04-04 23:50:50 +0000 | [diff] [blame] | 1 | /*
|
| 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 |
|
| 18 | package org.apache.felix.upnp.sample.tv;
|
| 19 |
|
| 20 | import java.util.Properties;
|
| 21 |
|
| 22 | import org.osgi.framework.BundleContext;
|
| 23 | import org.osgi.framework.Filter;
|
| 24 | import org.osgi.framework.ServiceRegistration;
|
| 25 | import org.osgi.service.upnp.UPnPDevice;
|
| 26 | import org.osgi.service.upnp.UPnPEventListener;
|
| 27 | import org.osgi.service.upnp.UPnPService;
|
| 28 |
|
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame^] | 29 | /*
|
| 30 | * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
|
| 31 | */
|
Francesco Furfari | c37181b | 2006-04-04 23:50:50 +0000 | [diff] [blame] | 32 |
|
| 33 | public 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 | }
|