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 "xpcom-config.h"
25 #include "nsServiceManagerUtils.h"
26 #include "nsEmbedString.h"
27 #include "nsIObserverService.h"
29 /* Project includes */
31 #include "aaIResource.h"
33 #include "aaIHandler.h"
37 :mHasEvent(PR_FALSE
), mAmount(0.0), mBroadcasting(PR_FALSE
)
45 NS_IMPL_ISUPPORTS2(aaFact
,
51 aaFact::GetId(PRInt64
*aId
)
53 NS_ENSURE_ARG_POINTER(aId
);
58 aaFact::SetId(PRInt64 aId
)
65 aaFact::Accept(aaIHandler
* aQuery
)
67 NS_ENSURE_ARG_POINTER(aQuery
);
68 return aQuery
->HandleFact(this);
72 aaFact::GetEdited(PRBool
* aEdited
)
74 NS_ENSURE_ARG_POINTER(aEdited
);
82 aaFact::GetEventId(PRInt64
*aEventId
)
84 NS_ENSURE_ARG_POINTER( aEventId
);
85 if (NS_UNLIKELY( !mHasEvent
))
86 return NS_ERROR_NOT_INITIALIZED
;
92 aaFact::GetTime(PRTime
*aTime
)
94 NS_ENSURE_ARG_POINTER( aTime
);
95 if (NS_UNLIKELY( !mHasEvent
))
96 return NS_ERROR_NOT_INITIALIZED
;
107 aaFact::SetEvent(aaIEvent
*aEvent
)
109 if (NS_UNLIKELY( ! aEvent
)) {
110 mHasEvent
= PR_FALSE
;
113 aEvent
->GetId( &mEventId
);
114 aEvent
->GetTime( &mTime
);
120 aaFact::GetTakeFrom(aaIFlow
* *aTakeFrom
)
122 NS_ENSURE_ARG_POINTER( aTakeFrom
);
123 NS_IF_ADDREF( *aTakeFrom
= mTakeFrom
);
127 aaFact::SetTakeFrom(aaIFlow
*aTakeFrom
)
129 mTakeFrom
= aTakeFrom
;
132 nsCOMPtr
<nsIObserverService
> broadcaster
= do_GetService(
133 "@mozilla.org/observer-service;1");
134 NS_ENSURE_TRUE(broadcaster
, NS_OK
);
135 broadcaster
->NotifyObservers(this, "fact-from-flow-change", nsnull
);
139 aaFact::PickTakeFrom()
145 aaFact::GetGiveTo(aaIFlow
* *aGiveTo
)
147 NS_ENSURE_ARG_POINTER( aGiveTo
);
148 NS_IF_ADDREF( *aGiveTo
= mGiveTo
);
152 aaFact::SetGiveTo(aaIFlow
*aGiveTo
)
157 nsCOMPtr
<nsIObserverService
> broadcaster
= do_GetService(
158 "@mozilla.org/observer-service;1");
159 NS_ENSURE_TRUE(broadcaster
, NS_OK
);
160 broadcaster
->NotifyObservers(this, "fact-to-flow-change", nsnull
);
170 aaFact::GetAmount(double *aAmount
)
172 NS_ENSURE_ARG_POINTER( aAmount
);
177 aaFact::SetAmount(double aAmount
)
190 aaFact::GetBroadcasting(PRBool
*aBroadcasting
)
192 NS_ENSURE_ARG_POINTER(aBroadcasting
);
193 *aBroadcasting
= mBroadcasting
;
197 aaFact::SetBroadcasting(PRBool aBroadcasting
)
199 mBroadcasting
= aBroadcasting
;