added functions to add and set credit, and _list function to easily use with xmlrpc2di

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@417 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 19 years ago
parent fa88fba332
commit 0d9ddae975

@ -31,8 +31,8 @@ CCAcc* CCAcc::instance()
}
CCAcc::CCAcc() {
// add some sample credits
credits["12345"] = 100;
// add some sample credits...
// credits["12345"] = 100;
}
CCAcc::~CCAcc() { }
@ -41,10 +41,20 @@ void CCAcc::invoke(const string& method, const AmArg& args, AmArg& ret)
{
if(method == "getCredit"){
ret.push(getCredit(args.get(0).asCStr()));
}
else if(method == "subtractCredit"){
} else if(method == "subtractCredit"){
ret.push(subtractCredit(args.get(0).asCStr(),
args.get(1).asInt()));
} else if(method == "addCredit"){
ret.push(addCredit(args.get(0).asCStr(),
args.get(1).asInt()));
} else if(method == "setCredit"){
ret.push(setCredit(args.get(0).asCStr(),
args.get(1).asInt()));
} else if(method == "_list"){
ret.push("getCredit");
ret.push("subtractCredit");
ret.push("setCredit");
ret.push("addCredit");
}
else
throw AmDynInvoke::NotImplemented(method);
@ -64,6 +74,20 @@ int CCAcc::getCredit(string pin) {
return res;
}
int CCAcc::setCredit(string pin, int amount) {
credits_mut.lock();
credits[pin] = amount;
credits_mut.unlock();
return amount;
}
int CCAcc::addCredit(string pin, int amount) {
credits_mut.lock();
int res = (credits[pin] += amount);
credits_mut.unlock();
return res;
}
int CCAcc::subtractCredit(string pin, int amount) {
credits_mut.lock();
map<string, unsigned int>::iterator it = credits.find(pin);

@ -12,6 +12,11 @@ class CCAcc : public AmDynInvoke
int getCredit(string pin);
/** returns remaining credit */
int subtractCredit(string pin, int amount);
/** adds some amount */
int addCredit(string pin, int amount);
/** sets the value to some amount */
int setCredit(string pin, int amount);
map<string, unsigned int> credits;
// as this is used from various sessions,

Loading…
Cancel
Save