blob: f6dfd85078d93e6c84a317e1213e5e40ff30f3cd [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 Furfarid8bdb642006-04-04 23:33:40 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid8bdb642006-04-04 23:33:40 +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 Furfarid8bdb642006-04-04 23:33:40 +000018 */
19
20package org.apache.felix.upnp.basedriver.importer.core.event.structs;
21
22import java.util.Dictionary;
23import java.util.Hashtable;
24import java.util.Vector;
25
26import org.osgi.service.upnp.UPnPEventListener;
27
Francesco Furfarif2a67912006-07-17 17:08:02 +000028/*
Karl Paulsd312acc2007-06-18 20:38:33 +000029* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000030*/
Francesco Furfarid8bdb642006-04-04 23:33:40 +000031public class Sid2Listeners {
32 private Hashtable sidListener;
33 private Hashtable alreadyfirst;
34
35 public Sid2Listeners() {
36 this.sidListener = new Hashtable();
37 this.alreadyfirst = new Hashtable();
38 }
39
40 public void put(String sid, UPnPEventListener listener) {
41 if (!sidListener.containsKey(sid)) {
42 Vector vec = new Vector();
43 vec.add(listener);
44 sidListener.put(sid, vec);
45 } else {
46 Vector vec = (Vector) sidListener.get(sid);
47 if (!vec.contains(listener)) {
48 vec.add(listener);
49 }
50 }
51 }
52
53 public final void remove(String sid) {
54 sidListener.remove(sid);
55 }
56
57 public final Vector get(String sid) {
58 return ((Vector) sidListener.get(sid));
59 }
60
61 /**
62 * @param sid
63 * @param dictionary
64 */
65 public boolean updateListeners(String sid, String deviceID,String serviceID, Dictionary dictionary) {
66
67 Vector listeners = (Vector) sidListener.get(sid);
68 if (listeners != null) {
69 for (int i = 0; i < listeners.size(); i++) {
70 UPnPEventListener listener = (UPnPEventListener) listeners.elementAt(i);
71 listener.notifyUPnPEvent(deviceID, serviceID, dictionary);
72 }
73 return true;
74 }
75 return false;
76 }
77
78 public boolean getAlreadyFirst(String sid) {
79 return ((Boolean) alreadyfirst.get(sid)).booleanValue();
80 }
81
82 public void setAlreadyFirst(String sid, boolean bool) {
83 alreadyfirst.put(sid, new Boolean(bool));
84 }
Karl Paulsd312acc2007-06-18 20:38:33 +000085}