sbDeviceEventTesterRemoval.h
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
28 #include <nsIRunnable.h>
29 #include "sbIDeviceEventListener.h"
30 
31 #include <nsAutoPtr.h>
32 #include <nsTArray.h>
33 #include <nsDataHashtable.h>
34 
35 /*
36  * event listener testing class - test removals
37  */
38 
40 
41 class sbDeviceEventTesterRemoval: public nsIRunnable
42 {
43 public:
45  NS_DECL_NSIRUNNABLE
46 
48 
49 private:
50  ~sbDeviceEventTesterRemoval();
51 
52 protected:
53  nsTArray<nsRefPtr<sbDeviceEventTesterRemovalHelper> > mListeners;
54 };
55 
57 {
58 public:
60  NS_DECL_SBIDEVICEEVENTLISTENER
61 
62  enum ACTION_TYPE {
63  ACTION_ADDREMOVE, // add or remove listener
64  ACTION_SET_FLAG, // set a flag (to true or false)
65  // flags default to false
66  ACTION_CHECK_FLAG, // check the flag
67  // for set=true: if flag is false, abort
68  // for set=false: if flag is set, do next (n) actions
69  // else skip next (n) actions (do rest)
71  };
72 
73  struct ACTION {
75  PRBool set;
76  nsCOMPtr<sbIDeviceEventListener> listener;
77  PRUint32 flag; // for set/check, which flag to use
78  PRUint32 count;
79 
80  ACTION(ACTION_TYPE aType, PRBool aSet, sbIDeviceEventListener* aListener)
81  : type(aType),
82  set(aSet),
83  listener(aListener)
84  {}
85 
86  ACTION(ACTION_TYPE aType, PRBool aSet, PRUint32 aFlag, PRUint32 aCount)
87  : type(aType),
88  set(aSet),
89  flag(aFlag),
90  count(aCount)
91  {}
92  };
93 
95 
96  nsresult AddAction(ACTION_TYPE aType,
97  PRBool aSet,
98  sbIDeviceEventListener* aListener)
99  { return AddAction(ACTION(aType, aSet, aListener)); }
100  nsresult AddAction(ACTION_TYPE aType, PRBool aSet, int aFlag, int aCount)
101  { return AddAction(ACTION(aType, aSet, aFlag, aCount)); }
102  nsresult AddAction(ACTION aAction);
103  nsresult SetFlag(PRUint32 aFlag, PRBool aSet);
104 
105 private:
107 
108 protected:
109  char mName;
110  nsTArray<ACTION> mActions;
111  nsDataHashtableMT<nsUint32HashKey, PRBool> mFlags;
112 };
nsresult AddAction(ACTION_TYPE aType, PRBool aSet, sbIDeviceEventListener *aListener)
nsresult SetFlag(PRUint32 aFlag, PRBool aSet)
nsCOMPtr< sbIDeviceEventListener > listener
nsresult AddAction(ACTION_TYPE aType, PRBool aSet, int aFlag, int aCount)
sbDeviceEventTesterRemovalHelper(const char aName)
ACTION(ACTION_TYPE aType, PRBool aSet, PRUint32 aFlag, PRUint32 aCount)
_updateCookies aName
NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE sbDeviceEventTesterRemoval()
nsTArray< nsRefPtr< sbDeviceEventTesterRemovalHelper > > mListeners
ACTION(ACTION_TYPE aType, PRBool aSet, sbIDeviceEventListener *aListener)
restoreHistoryPrecursor aCount
nsDataHashtableMT< nsUint32HashKey, PRBool > mFlags