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: */
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>
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>
38 :mHasEvent(PR_FALSE
), mAmount(0.0), mBroadcasting(PR_FALSE
)
46 NS_IMPL_ISUPPORTS2(aaFact
,
52 aaFact::GetId(PRInt64
*aId
)
54 NS_ENSURE_ARG_POINTER(aId
);
59 aaFact::SetId(PRInt64 aId
)
66 aaFact::Accept(aaIHandler
* aQuery
)
68 NS_ENSURE_ARG_POINTER(aQuery
);
69 return aQuery
->HandleFact(this);
73 aaFact::GetEdited(PRBool
* aEdited
)
75 NS_ENSURE_ARG_POINTER(aEdited
);
83 aaFact::GetEventId(PRInt64
*aEventId
)
85 NS_ENSURE_ARG_POINTER( aEventId
);
86 if (NS_UNLIKELY( !mHasEvent
))
87 return NS_ERROR_NOT_INITIALIZED
;
93 aaFact::GetTime(PRTime
*aTime
)
95 NS_ENSURE_ARG_POINTER( aTime
);
96 if (NS_UNLIKELY( !mHasEvent
))
97 return NS_ERROR_NOT_INITIALIZED
;
108 aaFact::SetEvent(aaIEvent
*aEvent
)
110 if (NS_UNLIKELY( ! aEvent
)) {
111 mHasEvent
= PR_FALSE
;
114 aEvent
->GetId( &mEventId
);
115 aEvent
->GetTime( &mTime
);
121 aaFact::GetTakeFrom(aaIFlow
* *aTakeFrom
)
123 NS_ENSURE_ARG_POINTER( aTakeFrom
);
124 NS_IF_ADDREF( *aTakeFrom
= mTakeFrom
);
128 aaFact::SetTakeFrom(aaIFlow
*aTakeFrom
)
130 mTakeFrom
= aTakeFrom
;
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
);
140 aaFact::PickTakeFrom()
146 aaFact::GetGiveTo(aaIFlow
* *aGiveTo
)
148 NS_ENSURE_ARG_POINTER( aGiveTo
);
149 NS_IF_ADDREF( *aGiveTo
= mGiveTo
);
153 aaFact::SetGiveTo(aaIFlow
*aGiveTo
)
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
);
171 aaFact::GetAmount(double *aAmount
)
173 NS_ENSURE_ARG_POINTER( aAmount
);
178 aaFact::SetAmount(double aAmount
)
191 aaFact::GetBroadcasting(PRBool
*aBroadcasting
)
193 NS_ENSURE_ARG_POINTER(aBroadcasting
);
194 *aBroadcasting
= mBroadcasting
;
198 aaFact::SetBroadcasting(PRBool aBroadcasting
)
200 mBroadcasting
= aBroadcasting
;