1 /*
2  * Copyright (C) 2011 Stefan Sayer
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * For a license to use the SEMS software under conditions
12  * other than those described here, or to purchase support for this
13  * software, please contact iptel.org by e-mail at the following addresses:
14  *    info@iptel.org
15  *
16  * SEMS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25 
26 #ifndef _CC_TEMPLATE_H
27 #define _CC_TEMPLATE_H
28 
29 #include "AmApi.h"
30 
31 #include "SBCCallProfile.h"
32 
33 #include <map>
34 
35 /**
36  * sample call control module
37  */
38 class Prepaid : public AmDynInvoke
39 {
40   static Prepaid* _instance;
41 
PrepaidFactory(const string & name)42   std::map<string, unsigned int> credits;
43   AmMutex credits_mut;
44 
getInstance()45 
46   /** @returns credit for pin, found=false if pin wrong */
47   int getCredit(string pin, bool& found);
48   /** @returns remaining credit */
onLoad()49   int subtractCredit(string pin, int amount, bool& found);
50 
51   /** adds some amount */
52   int addCredit(string pin, int amount);
53   /** sets the value to some amount */
54   int setCredit(string pin, int amount);
55 
56 
57   void start(const string& cc_name, const string& ltag, SBCCallProfile* call_profile,
58 	     int start_ts_sec, int start_ts_usec, const AmArg& values,
59 	     int timer_id, AmArg& res);
60   void connect(const string& cc_name, const string& ltag, SBCCallProfile* call_profile,
61 	       const string& other_ltag,
62 	       int connect_ts_sec, int connect_ts_usec);
instance()63   void end(const string& cc_name, const string& ltag, SBCCallProfile* call_profile,
64 	   int start_ts_sec, int start_ts_usec,
65 	   int connect_ts_sec, int connect_ts_usec,
66 	   int end_ts_sec, int end_ts_usec);
67 
68  public:
69   Prepaid();
Prepaid()70   ~Prepaid();
71   static Prepaid* instance();
72   void invoke(const string& method, const AmArg& args, AmArg& ret);
73   int onLoad();
~Prepaid()74 };
75 
onLoad()76 #endif
77