[xpunit] Rename from 'cxxunit' and switch to mozbuild (bug #114)
[abstract.git] / base / aaFact.cpp
blob30fbb1286f6d0176f59611cfc9cffcb1d391de9f
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) 2007 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 <abstract/aacore.h>
24 #include "nsCOMPtr.h"
25 #include "nsServiceManagerUtils.h"
26 #include "nsEmbedString.h"
27 #include "nsIObserverService.h"
29 /* Project includes */
30 #include <abstract/base/aaIFlow.h>
31 #include <abstract/base/aaIResource.h>
32 #include <abstract/base/aaIFact.h>
33 #include <abstract/base/aaIEvent.h>
34 #include <abstract/base/aaIHandler.h>
35 #include "aaFact.h"
37 aaFact::aaFact()
38 :mHasEvent(PR_FALSE), mAmount(0.0), mBroadcasting(PR_FALSE)
42 aaFact::~aaFact()
46 NS_IMPL_ISUPPORTS2(aaFact,
47 aaIDataNode,
48 aaIFact)
50 /* aaIDataNode */
51 NS_IMETHODIMP
52 aaFact::GetId(PRInt64 *aId)
54 NS_ENSURE_ARG_POINTER(aId);
55 *aId = mId;
56 return NS_OK;
58 NS_IMETHODIMP
59 aaFact::SetId(PRInt64 aId)
61 mId = aId;
62 return NS_OK;
65 NS_IMETHODIMP
66 aaFact::Accept(aaIHandler* aQuery)
68 NS_ENSURE_ARG_POINTER(aQuery);
69 return aQuery->HandleFact(this);
72 NS_IMETHODIMP
73 aaFact::GetEdited(PRBool* aEdited)
75 NS_ENSURE_ARG_POINTER(aEdited);
76 *aEdited = PR_FALSE;
77 return NS_OK;
81 /* aaIFact */
82 NS_IMETHODIMP
83 aaFact::GetEventId(PRInt64 *aEventId)
85 NS_ENSURE_ARG_POINTER( aEventId );
86 if (NS_UNLIKELY( !mHasEvent ))
87 return NS_ERROR_NOT_INITIALIZED;
88 *aEventId = mEventId;
89 return NS_OK;
92 NS_IMETHODIMP
93 aaFact::GetTime(PRTime *aTime)
95 NS_ENSURE_ARG_POINTER( aTime );
96 if (NS_UNLIKELY( !mHasEvent ))
97 return NS_ERROR_NOT_INITIALIZED;
98 *aTime = mTime;
99 return NS_OK;
101 PRTime
102 aaFact::PickTime()
104 return mTime;
107 NS_IMETHODIMP
108 aaFact::SetEvent(aaIEvent *aEvent)
110 if (NS_UNLIKELY( ! aEvent )) {
111 mHasEvent = PR_FALSE;
112 return NS_OK;
114 aEvent->GetId( &mEventId );
115 aEvent->GetTime( &mTime );
116 mHasEvent = PR_TRUE;
117 return NS_OK;
120 NS_IMETHODIMP
121 aaFact::GetTakeFrom(aaIFlow * *aTakeFrom)
123 NS_ENSURE_ARG_POINTER( aTakeFrom );
124 NS_IF_ADDREF( *aTakeFrom = mTakeFrom );
125 return NS_OK;
127 NS_IMETHODIMP
128 aaFact::SetTakeFrom(aaIFlow *aTakeFrom)
130 mTakeFrom = aTakeFrom;
131 if (! mBroadcasting)
132 return NS_OK;
133 nsCOMPtr<nsIObserverService> broadcaster = do_GetService(
134 "@mozilla.org/observer-service;1");
135 NS_ENSURE_TRUE(broadcaster, NS_OK);
136 broadcaster->NotifyObservers(this, "fact-from-flow-change", nsnull);
137 return NS_OK;
139 aaIFlow *
140 aaFact::PickTakeFrom()
142 return mTakeFrom;
145 NS_IMETHODIMP
146 aaFact::GetGiveTo(aaIFlow * *aGiveTo)
148 NS_ENSURE_ARG_POINTER( aGiveTo );
149 NS_IF_ADDREF( *aGiveTo = mGiveTo );
150 return NS_OK;
152 NS_IMETHODIMP
153 aaFact::SetGiveTo(aaIFlow *aGiveTo)
155 mGiveTo = aGiveTo;
156 if (! mBroadcasting)
157 return NS_OK;
158 nsCOMPtr<nsIObserverService> broadcaster = do_GetService(
159 "@mozilla.org/observer-service;1");
160 NS_ENSURE_TRUE(broadcaster, NS_OK);
161 broadcaster->NotifyObservers(this, "fact-to-flow-change", nsnull);
162 return NS_OK;
164 aaIFlow *
165 aaFact::PickGiveTo()
167 return mGiveTo;
170 NS_IMETHODIMP
171 aaFact::GetAmount(double *aAmount)
173 NS_ENSURE_ARG_POINTER( aAmount );
174 *aAmount = mAmount;
175 return NS_OK;
177 NS_IMETHODIMP
178 aaFact::SetAmount(double aAmount)
180 mAmount = aAmount;
181 return NS_OK;
184 double
185 aaFact::PickAmount()
187 return mAmount;
190 NS_IMETHODIMP
191 aaFact::GetBroadcasting(PRBool *aBroadcasting)
193 NS_ENSURE_ARG_POINTER(aBroadcasting);
194 *aBroadcasting = mBroadcasting;
195 return NS_OK;
197 NS_IMETHODIMP
198 aaFact::SetBroadcasting(PRBool aBroadcasting)
200 mBroadcasting = aBroadcasting;
201 return NS_OK;