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 "nsComponentManagerUtils.h"
27 #include "nsIObserverService.h"
29 #include "nsIClassInfoImpl.h"
31 /* Project includes */
32 #include "aaIResource.h"
33 #include "aaIBalance.h"
34 #include "aaIHandler.h"
35 #include "aaBaseKeys.h"
40 :mEdited(0), mHasTime(PR_FALSE
), mRate(1.0), mDiff(0.0)
49 NS_IMPL_ISUPPORTS2_CI(aaQuote
,
54 aaQuote::GetId(PRInt64
*aId
)
56 NS_ENSURE_ARG_POINTER(aId
);
57 return NS_ERROR_NOT_IMPLEMENTED
;
60 aaQuote::SetId(PRInt64 aId
)
62 return NS_ERROR_NOT_IMPLEMENTED
;
66 aaQuote::Accept(aaIHandler
* aQuery
)
68 NS_ENSURE_ARG_POINTER(aQuery
);
69 return aQuery
->HandleQuote(this);
73 aaQuote::GetEdited(PRBool
* aEdited
)
75 NS_ENSURE_ARG_POINTER(aEdited
);
81 aaQuote::Sync(aaIStorager
*aStorager
, aaISqliteChannel
*aChannel
)
83 return NS_ERROR_NOT_IMPLEMENTED
;
88 aaQuote::GetResource(aaIResource
** aResource
)
90 NS_ENSURE_ARG_POINTER(aResource
);
91 NS_IF_ADDREF(*aResource
= mResource
);
95 aaQuote::SetResource(aaIResource
* aResource
)
97 if (mResource
== aResource
)
99 mResource
= aResource
;
101 nsCOMPtr
<nsIObserverService
> broadcaster
= do_GetService(
102 "@mozilla.org/observer-service;1");
103 NS_ENSURE_TRUE(broadcaster
, NS_OK
);
104 broadcaster
->NotifyObservers(this, "quote-resource-change", nsnull
);
108 aaQuote::PickResource()
114 aaQuote::GetTime(PRTime
*aTime
)
116 NS_ENSURE_TRUE( mHasTime
, NS_ERROR_NOT_INITIALIZED
);
117 NS_ENSURE_ARG_POINTER( aTime
);
122 aaQuote::SetTime(PRTime aTime
)
136 aaQuote::GetRate(double *aRate
)
138 NS_ENSURE_ARG_POINTER(aRate
);
143 aaQuote::SetRate(double aRate
)
156 aaQuote::GetDiff(double *aDiff
)
158 NS_ENSURE_ARG_POINTER(aDiff
);
163 aaQuote::SetDiff(double aDiff
)
175 aaQuote::InitIncome(aaIBalance
*aIncome
)
178 if (NS_UNLIKELY(mIncome
)) return NS_ERROR_ALREADY_INITIALIZED
;
180 nsCOMPtr
<aaIBalance
> income
= aIncome
;
182 income
= do_CreateInstance(AA_INCOME_CONTRACT
, &rv
);
183 NS_ENSURE_SUCCESS(rv
, rv
);
186 rv
= income
->ApplyQuote(this);
187 NS_ENSURE_SUCCESS(rv
, rv
);
193 aaQuote::GetIncome(aaIBalance
* *aIncome
)
195 NS_ENSURE_ARG_POINTER(aIncome
);
196 NS_IF_ADDREF(*aIncome
= mIncome
);