transport: pass correct channel
[abstract.git] / report / aaTranscriptCounter.cpp
blobe303d6170df99feca2f4a7f011ddbafc73a03827
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,2008 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"
26 /* Unfrozen API */
28 /* Project includes */
29 #include "aaIFlow.h"
30 #include "aaIFact.h"
31 #include "aaITransaction.h"
32 #include "aaTranscript.h"
33 #include "aaTranscriptCounter.h"
35 aaTranscriptCounter::aaTranscriptCounter(aaTranscript *aTarget)
36 :mTarget(aTarget)
40 NS_IMPL_ISUPPORTS1(aaTranscriptCounter,
41 aaILoadObserver)
43 NS_IMETHODIMP
44 aaTranscriptCounter::ObserveLoad(aaIDataNode *aNode)
46 NS_ENSURE_ARG_POINTER(mTarget);
47 nsresult rv;
48 nsCOMPtr<aaITransaction> txn = do_QueryInterface(aNode, &rv);
49 NS_ENSURE_SUCCESS(rv, rv);
50 NS_ENSURE_TRUE(txn->PickFact(), NS_ERROR_UNEXPECTED);
52 if (!mTarget->mFlow->PickId()) {
53 if (txn->PickEarnings() > 0.0)
54 mTarget->mTotalCreditsValue += txn->PickEarnings();
55 else
56 mTarget->mTotalDebitsValue -= txn->PickEarnings();
58 mTarget->mList.AppendObject(txn);
59 return NS_OK;
62 if (txn->PickFact()->PickGiveTo()
63 && txn->PickFact()->PickGiveTo()->PickId() == mTarget->mFlow->PickId())
65 mTarget->mTotalDebits += txn->PickFact()->PickAmount();
66 mTarget->mTotalDebitsValue += txn->PickValue() + txn->PickEarnings();
68 else if (txn->PickFact()->PickTakeFrom()
69 && txn->PickFact()->PickTakeFrom()->PickId() == mTarget->mFlow->PickId())
71 mTarget->mTotalCredits += txn->PickFact()->PickAmount();
72 mTarget->mTotalCreditsValue += txn->PickValue();
74 else {
75 return NS_ERROR_UNEXPECTED;
78 mTarget->mList.AppendObject(txn);
79 return NS_OK;
82 NS_IMETHODIMP
83 aaTranscriptCounter::ObserveResults()
85 return NS_OK;