33 #include <nsIMutableArray.h>
35 #include <nsComponentManagerUtils.h>
42 static PRLogModuleInfo* gMediacoreVotingChain = nsnull;
43 #define TRACE(args) PR_LOG(gMediacoreVotingChain, PR_LOG_DEBUG, args)
44 #define LOG(args) PR_LOG(gMediacoreVotingChain, PR_LOG_WARN, args)
59 if (!gMediacoreVotingChain)
60 gMediacoreVotingChain= PR_NewLogModule(
"sbMediacoreVotingChain");
63 TRACE((
"sbMediacoreVotingChain[0x%x] - Created",
this));
68 TRACE((
"sbMediacoreVotingChain[0x%x] - Destroyed",
this));
72 nsAutoLock::DestroyLock(
mLock);
81 TRACE((
"sbMediacoreVotingChain[0x%x] - Init",
this));
83 mLock = nsAutoLock::NewLock(
"sbMediacoreVotingChain::mLock");
84 NS_ENSURE_TRUE(
mLock, NS_ERROR_OUT_OF_MEMORY);
93 TRACE((
"sbMediacoreVotingChain[0x%x] - AddVoteResult",
this));
94 NS_ENSURE_TRUE(
mLock, NS_ERROR_NOT_INITIALIZED);
95 NS_ENSURE_ARG_POINTER(aMediacore);
97 nsAutoLock lock(
mLock);
104 sbMediacoreVotingChain::GetValid(PRBool *aValid)
106 TRACE((
"sbMediacoreVotingChain[0x%x] - GetValid",
this));
107 NS_ENSURE_TRUE(
mLock, NS_ERROR_NOT_INITIALIZED);
108 NS_ENSURE_ARG_POINTER(aValid);
110 nsAutoLock lock(
mLock);
117 sbMediacoreVotingChain::GetMediacoreChain(nsIArray * *aMediacoreChain)
119 TRACE((
"sbMediacoreVotingChain[0x%x] - GetMediacoreChain",
this));
120 NS_ENSURE_TRUE(
mLock, NS_ERROR_NOT_INITIALIZED);
121 NS_ENSURE_ARG_POINTER(aMediacoreChain);
123 nsresult rv = NS_ERROR_UNEXPECTED;
124 nsCOMPtr<nsIMutableArray> mutableArray =
125 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
126 NS_ENSURE_SUCCESS(rv, rv);
128 nsAutoLock lock(
mLock);
130 votingmap_t::const_reverse_iterator cit =
mResults.rbegin();
131 votingmap_t::const_reverse_iterator endCit =
mResults.rend();
133 for(; cit != endCit; ++cit) {
134 rv = mutableArray->AppendElement((*cit).second, PR_FALSE);
135 NS_ENSURE_SUCCESS(rv, rv);
138 rv = CallQueryInterface(mutableArray, aMediacoreChain);
139 NS_ENSURE_SUCCESS(rv, rv);
145 sbMediacoreVotingChain::GetVote(
sbIMediacore *aMediacore,
148 TRACE((
"sbMediacoreVotingChain[0x%x] - GetVote",
this));
149 NS_ENSURE_TRUE(
mLock, NS_ERROR_NOT_INITIALIZED);
150 NS_ENSURE_ARG_POINTER(aMediacore);
151 NS_ENSURE_ARG_POINTER(_retval);
153 nsAutoLock lock(
mLock);
155 votingmap_t::const_reverse_iterator cit =
mResults.rbegin();
156 votingmap_t::const_reverse_iterator endCit =
mResults.rend();
157 for(; cit != endCit; ++cit) {
158 if((*cit).second == aMediacore) {
159 *_retval = (*cit).first;
164 return NS_ERROR_NOT_AVAILABLE;