transport: sqlite channel load group attribute
[abstract.git] / base / aaQuote.cpp
blobe2dc188ae4fe006d9422c1043ea11e85cbe70039
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 "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsServiceManagerUtils.h"
26 #include "nsComponentManagerUtils.h"
27 #include "nsIObserverService.h"
28 #include "nsMemory.h"
29 #include "nsIClassInfoImpl.h"
31 /* Project includes */
32 #include "aaIResource.h"
33 #include "aaIBalance.h"
34 #include "aaIHandler.h"
35 #include "aaBaseKeys.h"
37 #include "aaQuote.h"
39 aaQuote::aaQuote()
40 :mEdited(0), mHasTime(PR_FALSE), mRate(1.0), mDiff(0.0)
45 aaQuote::~aaQuote()
49 NS_IMPL_ISUPPORTS2_CI(aaQuote,
50 aaIDataNode,
51 aaIQuote)
52 /* aaIDataNode */
53 NS_IMETHODIMP
54 aaQuote::GetId(PRInt64 *aId)
56 NS_ENSURE_ARG_POINTER(aId);
57 return NS_ERROR_NOT_IMPLEMENTED;
59 NS_IMETHODIMP
60 aaQuote::SetId(PRInt64 aId)
62 return NS_ERROR_NOT_IMPLEMENTED;
65 NS_IMETHODIMP
66 aaQuote::Accept(aaIHandler* aQuery)
68 NS_ENSURE_ARG_POINTER(aQuery);
69 return aQuery->HandleQuote(this);
72 NS_IMETHODIMP
73 aaQuote::GetEdited(PRBool* aEdited)
75 NS_ENSURE_ARG_POINTER(aEdited);
76 *aEdited = mEdited;
77 return NS_OK;
80 NS_IMETHODIMP
81 aaQuote::Sync(aaIStorager *aStorager, aaISqliteChannel *aChannel)
83 return NS_ERROR_NOT_IMPLEMENTED;
86 /* aaIQuote */
87 NS_IMETHODIMP
88 aaQuote::GetResource(aaIResource ** aResource)
90 NS_ENSURE_ARG_POINTER(aResource);
91 NS_IF_ADDREF(*aResource = mResource);
92 return NS_OK;
94 NS_IMETHODIMP
95 aaQuote::SetResource(aaIResource * aResource)
97 if (mResource == aResource)
98 return NS_OK;
99 mResource = aResource;
100 mEdited = PR_TRUE;
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);
105 return NS_OK;
107 aaIResource*
108 aaQuote::PickResource()
110 return mResource;
113 NS_IMETHODIMP
114 aaQuote::GetTime(PRTime *aTime)
116 NS_ENSURE_TRUE( mHasTime, NS_ERROR_NOT_INITIALIZED);
117 NS_ENSURE_ARG_POINTER( aTime );
118 *aTime = mTime;
119 return NS_OK;
121 NS_IMETHODIMP
122 aaQuote::SetTime(PRTime aTime)
124 mTime = aTime;
125 mHasTime = PR_TRUE;
126 mEdited = PR_TRUE;
127 return NS_OK;
129 PRInt64
130 aaQuote::PickTime()
132 return mTime;
135 NS_IMETHODIMP
136 aaQuote::GetRate(double *aRate)
138 NS_ENSURE_ARG_POINTER(aRate);
139 *aRate = mRate;
140 return NS_OK;
142 NS_IMETHODIMP
143 aaQuote::SetRate(double aRate)
145 mRate = aRate;
146 mEdited = PR_TRUE;
147 return NS_OK;
149 double
150 aaQuote::PickRate()
152 return mRate;
155 NS_IMETHODIMP
156 aaQuote::GetDiff(double *aDiff)
158 NS_ENSURE_ARG_POINTER(aDiff);
159 *aDiff = mDiff;
160 return NS_OK;
162 NS_IMETHODIMP
163 aaQuote::SetDiff(double aDiff)
165 mDiff = aDiff;
166 return NS_OK;
168 double
169 aaQuote::PickDiff()
171 return mDiff;
174 NS_IMETHODIMP
175 aaQuote::InitIncome(aaIBalance *aIncome)
177 nsresult rv;
178 if (NS_UNLIKELY(mIncome)) return NS_ERROR_ALREADY_INITIALIZED;
180 nsCOMPtr<aaIBalance> income = aIncome;
181 if (!income) {
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);
189 mIncome = income;
190 return NS_OK;
192 NS_IMETHODIMP
193 aaQuote::GetIncome(aaIBalance * *aIncome)
195 NS_ENSURE_ARG_POINTER(aIncome);
196 NS_IF_ADDREF(*aIncome = mIncome);
197 return NS_OK;