transport: pass correct channel
[abstract.git] / base / aaEventBase.cpp
blob252e96d2c4da69afd49485a815d57fb111a88868
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsStringAPI.h"
26 #include "nsIMutableArray.h"
27 #include "nsCOMArray.h"
29 /* Project includes */
30 #include "aaIRule.h"
31 #include "aaIFact.h"
32 #include "aaIHandler.h"
33 #include "aaIStorager.h"
35 #include "aaEventBase.h"
36 #include "aaEvent.h"
39 aaEventBase::aaEventBase(aaEvent *aParent)
40 :mParent(aParent), mId(0), mTag((const PRUnichar *) nsnull),
41 mHasTime(PR_FALSE), mRead(PR_FALSE), mEdited(PR_FALSE)
45 aaEventBase::~aaEventBase()
49 NS_IMPL_ISUPPORTS5(aaEventBase,
50 aaIDataNode,
51 aaIListNode,
52 aaIEvent,
53 nsIArray,
54 nsIMutableArray)
55 /* aaIDataNode */
56 NS_IMETHODIMP
57 aaEventBase::GetId(PRInt64 *aId)
59 NS_ENSURE_ARG_POINTER(aId);
60 *aId = mId;
61 return NS_OK;
63 NS_IMETHODIMP
64 aaEventBase::SetId(PRInt64 aId)
66 mId = aId;
67 return NS_OK;
69 PRInt64
70 aaEventBase::PickId()
72 return mId;
75 NS_IMETHODIMP
76 aaEventBase::Accept(aaIHandler* aQuery)
78 NS_ENSURE_ARG_POINTER(aQuery);
79 nsresult rv;
80 rv = aQuery->HandleEvent(this);
81 if (NS_FAILED(rv)) return rv;
83 PRInt32 i;
84 for (i = 0; i < mFacts.Count(); i++) {
85 rv = mFacts[i]->Accept(aQuery);
86 NS_ENSURE_SUCCESS(rv, rv);
89 return NS_OK;
92 NS_IMETHODIMP
93 aaEventBase::GetEdited(PRBool* aEdited)
95 NS_ENSURE_ARG_POINTER(aEdited);
96 *aEdited = mEdited;
97 return NS_OK;
100 NS_IMETHODIMP
101 aaEventBase::Sync(aaIStorager *aStorager, aaISqliteChannel *aChannel)
103 nsresult rv;
104 if (mId) {
105 rv = aStorager->Delete(aChannel);
106 NS_ENSURE_SUCCESS(rv, rv);
108 else {
109 rv = aStorager->Insert(aChannel);
110 if (NS_FAILED(rv)) return rv;
113 return NS_OK;
116 /* aaIEvent */
117 NS_IMETHODIMP
118 aaEventBase::GetTag(nsAString & aTag)
120 aTag.Assign(mTag);
121 mRead = PR_TRUE;
122 return NS_OK;
124 NS_IMETHODIMP
125 aaEventBase::SetTag(const nsAString & aTag)
127 if (mTag.Equals(aTag))
128 return NS_OK;
129 if (mRead)
130 mEdited = PR_TRUE;
131 mTag.Assign(aTag);
132 return NS_OK;
135 NS_IMETHODIMP
136 aaEventBase::GetTime(PRTime *aTime)
138 NS_ENSURE_TRUE( mHasTime, NS_ERROR_NOT_INITIALIZED);
139 NS_ENSURE_ARG_POINTER( aTime );
140 *aTime = mTime;
141 return NS_OK;
143 NS_IMETHODIMP
144 aaEventBase::SetTime(PRTime aTime)
146 PRExplodedTime tm;
147 PR_ExplodeTime(aTime, &PR_LocalTimeParameters, &tm);
148 tm.tm_params.tp_gmt_offset = 0;
149 tm.tm_params.tp_dst_offset = 0;
150 tm.tm_hour = 12;
151 tm.tm_min = 0;
152 tm.tm_sec = 0;
153 tm.tm_usec = 0;
154 mTime = PR_ImplodeTime(&tm);
155 mHasTime = PR_TRUE;
156 return NS_OK;
159 /* nsIArray */
160 NS_IMETHODIMP
161 aaEventBase::GetLength(PRUint32 *aLength)
163 NS_ENSURE_ARG_POINTER( aLength );
164 *aLength = mFacts.Count();
165 return NS_OK;
168 NS_IMETHODIMP
169 aaEventBase::QueryElementAt(PRUint32 index, const nsIID & uuid, void * *result)
171 NS_ENSURE_TRUE( index < (PRUint32) mFacts.Count(), NS_ERROR_INVALID_ARG);
172 NS_ENSURE_ARG_POINTER( result );
173 return mFacts[index]->QueryInterface(uuid, result);
176 NS_IMETHODIMP
177 aaEventBase::IndexOf(PRUint32 startIndex, nsISupports *element, PRUint32 *_retval)
179 return NS_ERROR_NOT_IMPLEMENTED;
182 NS_IMETHODIMP
183 aaEventBase::Enumerate(nsISimpleEnumerator **_retval)
185 return NS_ERROR_NOT_IMPLEMENTED;
188 /* nsIMutableArray */
189 NS_IMETHODIMP
190 aaEventBase::AppendElement(nsISupports *element, PRBool weak)
192 NS_ENSURE_TRUE(!weak, NS_ERROR_NOT_IMPLEMENTED);
193 nsCOMPtr<aaIFact> fact = do_QueryInterface(element);
194 NS_ENSURE_TRUE(fact, NS_ERROR_INVALID_ARG);
196 nsresult rv;
197 rv = fact->SetEvent(mParent);
198 NS_ENSURE_SUCCESS(rv, rv);
200 PRBool res = mFacts.AppendObject(fact);
201 NS_ENSURE_TRUE(res, NS_ERROR_FAILURE);
203 return NS_OK;
206 NS_IMETHODIMP
207 aaEventBase::RemoveElementAt(PRUint32 index)
209 return NS_ERROR_NOT_IMPLEMENTED;
212 NS_IMETHODIMP
213 aaEventBase::InsertElementAt(nsISupports *element, PRUint32 index, PRBool weak)
215 return NS_ERROR_NOT_IMPLEMENTED;
218 NS_IMETHODIMP
219 aaEventBase::ReplaceElementAt(nsISupports *element, PRUint32 index, PRBool weak)
221 return NS_ERROR_NOT_IMPLEMENTED;
224 NS_IMETHODIMP
225 aaEventBase::Clear()
227 mFacts.Clear();
228 return NS_OK;