Remove dynamic exceptions
[anna.git] / include / anna / diameter / app / dcca / Message.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_diameter_app_dcca_Message_hpp
10 #define anna_diameter_app_dcca_Message_hpp
11
12
13 // Local
14 #include <anna/diameter/app/base/Message.hpp>
15
16 // AVPID's
17 #include <anna/diameter/helpers/base/defines.hpp>
18 #include <anna/diameter/helpers/tgpp/defines.hpp>
19 #include <anna/diameter/helpers/dcca/defines.hpp>
20
21 #include <anna/core/RuntimeException.hpp>
22
23 // STL
24 #include <string>
25
26
27 //------------------------------------------------------------------------------
28 //---------------------------------------------------------------------- #define
29 //------------------------------------------------------------------------------
30
31
32
33 namespace anna {
34
35 namespace diameter {
36
37 namespace codec {
38 using namespace basetypes;
39 }
40
41 namespace app {
42
43 namespace dcca {
44
45
46
47 typedef struct {
48
49   std::string qosProfile;
50   int Release;
51   int TrafficClass;
52   int HandlingPriority;
53   int MaximumBitrateForUplink;
54   int MaximumBitrateForDownlink;
55
56
57   void reset() {
58     qosProfile = "";
59     Release = TrafficClass = HandlingPriority = MaximumBitrateForUplink = MaximumBitrateForDownlink = 0;
60   }
61
62 } qosProfile_t;
63
64
65
66
67 /**
68 * Diameter message for DCCA (diameter credit control application)
69 */
70 class Message : public anna::diameter::app::base::Message {
71
72   qosProfile_t a_qosProfile;
73
74 public:
75
76   /**
77      Avp Subscription-Id-Data data-part pointer reference.
78
79      @param Subscription-Id-Type value to filter the search. END_USER_E164 by default.
80      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
81   */
82   const UTF8String * getSubscriptionIdData(int subscriptionIdType = helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
83     ASSERT_APP_GETAVP(
84       const anna::diameter::codec::Avp * sid;
85       int pos = 1;
86
87       while((sid = getAvp(helpers::dcca::AVPID__Subscription_Id, pos++)))
88       if(subscriptionIdType == sid->getAvp(helpers::dcca::AVPID__Subscription_Id_Type)->getEnumerated()->getValue())
89         return sid->getAvp(helpers::dcca::AVPID__Subscription_Id_Data)->getUTF8String();
90         return NULL;
91       );
92   }
93
94   /**
95      Avp Multiple-Services-Credit-Control pointer reference
96      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
97   */
98   const anna::diameter::codec::Avp * getMultipleServicesCreditControl(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
99     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control));
100   }
101
102   /**
103      Avp Service-Identifier data-part pointer reference
104      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
105   */
106   const Unsigned32 * getServiceIdentifier(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
107     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Service_Identifier)->getUnsigned32());
108   }
109
110   /**
111      Avp Rating-Group data-part pointer reference
112      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
113   */
114   const Unsigned32 * getRatingGroup(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
115     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Rating_Group)->getUnsigned32());
116   }
117
118   /**
119      Avp Tariff-Change-Usage data-part pointer reference
120      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
121   */
122   const Enumerated * getTariffChangeUsage(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
123     ASSERT_APP_GETAVP(
124       return   getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->
125                getAvp(helpers::dcca::AVPID__Used_Service_Unit)->
126                getAvp(helpers::dcca::AVPID__Tariff_Change_Usage)->getEnumerated();
127     );
128   }
129
130   /**
131      Avp Validity-Time data-part pointer reference
132      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
133   */
134   const Unsigned32 * getValidityTime(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
135     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Validity_Time)->getUnsigned32());
136   }
137
138   /**
139      Avp Requested-Service-Unit pointer reference
140      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
141   */
142   const anna::diameter::codec::Avp * getRequestedServiceUnit(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
143     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->getAvp(helpers::dcca::AVPID__Requested_Service_Unit));
144   }
145
146   /**
147      Avp n-th Used-Service-Unit pointer reference
148      @param ocurrence Select the n-th USU within the MSCC. First by default.
149      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
150   */
151   const anna::diameter::codec::Avp * getUsedServiceUnit(int ocurrence = 1, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
152     ASSERT_APP_GETAVP(
153       return   getAvp(helpers::dcca::AVPID__Multiple_Services_Credit_Control)->
154                getAvp(helpers::dcca::AVPID__Used_Service_Unit, ocurrence);
155     );
156   }
157
158   /**
159      Avp CC_Request_Type data-part pointer reference
160      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
161   */
162   const Enumerated * getCCRequestType(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
163     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__CC_Request_Type)->getEnumerated());
164   }
165
166   /**
167      Avp CC_Request_Number data-part pointer reference
168      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
169   */
170   const Unsigned32 * getCCRequestNumber(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
171     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__CC_Request_Number)->getUnsigned32());
172   }
173
174   /**
175      Avp Multiple-Services-Indicator data-part pointer reference
176      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
177   */
178   const Enumerated * getMultipleServicesIndicator(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
179     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Multiple_Services_Indicator)->getEnumerated());
180   }
181
182   /**
183      Avp Service-Context-Id data-part pointer reference
184      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
185   */
186   const UTF8String * getServiceContextId(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
187     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__Service_Context_Id)->getUTF8String());
188   }
189
190   /**
191      Avp 3GPP-NSAPI data-part pointer reference
192      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
193   */
194   const UTF8String * get3GPPNSAPI(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
195     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_NSAPI)->getUTF8String());
196   }
197
198   /**
199      Avp 3GPP-Selection-Mode data-part pointer reference
200      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
201   */
202   const UTF8String * get3GPPSelectionMode(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
203     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_Selection_Mode)->getUTF8String());
204   }
205
206   /**
207      Avp 3GPP-Session-Stop-Indicator data-part pointer reference
208      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
209   */
210   const OctetString * get3GPPSessionStopIndicator(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
211     ASSERT_APP_GETAVP(return getAvp(helpers::tgpp::AVPID__3GPP_Session_Stop_Indicator)->getOctetString());
212   }
213
214   /**
215      Avp User-Equipment-Info pointer reference
216      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
217   */
218   const anna::diameter::codec::Avp * getUserEquipmentInfo(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
219     ASSERT_APP_GETAVP(return getAvp(helpers::dcca::AVPID__User_Equipment_Info));
220   }
221
222   /**
223      Avp User-Equipment-Info-Value data-part pointer reference.
224
225      @param User-Equipment-Info-Type value to filter the search. IMEISV by default.
226      @param emode Excepcion mode handling when avp is not found: Ignore (no action is taken but debug trace), Throw (exception launched, by default), Trace (trace warning).
227   */
228   const OctetString * getUserEquipmentInfoValue(int userEquipmentInfoType = helpers::dcca::AVPVALUES__User_Equipment_Info_Type::IMEISV, anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) {
229     ASSERT_APP_GETAVP(
230       const anna::diameter::codec::Avp * uei;
231       int pos = 1;
232
233       while((uei = getAvp(helpers::dcca::AVPID__User_Equipment_Info, pos++)))
234       if(userEquipmentInfoType == uei->getAvp(helpers::dcca::AVPID__User_Equipment_Info_Type)->getEnumerated()->getValue())
235         return uei->getAvp(helpers::dcca::AVPID__User_Equipment_Info_Value)->getOctetString();
236         return NULL;
237       );
238   }
239
240   // there has to be at least one out-of-line definition of a non-pure-virtual function (http://www.daniweb.com/software-development/cpp/threads/114299/undefined-reference-to-vtable-for-)
241   // Lo que dice es que las virtuales no puras de una clase deben tener al menos una definicion en el .cc (lo contrario de in-line). Parece una limitaciĆ³n del compilador.
242   // Podemos hacer una definicion por defecto (return NULL), o mejor, hacerla virtual pura (porque se necesitara por parte del decodificador de QoS):
243   virtual const UTF8String * get3GPPGPRSNegQoSProfile(anna::Exception::Mode::_v emode = anna::Exception::Mode::Throw) noexcept(false) = 0;
244
245
246   /**
247      Decodes 3GPP-GPRS-Neg-QoS-Profile (as described in 3GPP TS 24.008)
248
249      @return 3GPP-GPRS-Neg-QoS-Profile decoded on struct
250   */
251   const qosProfile_t & decode3GPPGPRSNegQoSProfile() noexcept(false);
252
253
254
255 //   static bool dameTiempoConsumido(const InfoDIAMETER & mensaje,long &tiempoConsumidoAntesConmutacion,long &tiempoConsumidoDespuesConmutacion,long &tiempoConsumidoSinConmutacion);
256 //   static bool dameTiempoConsumido(const InfoDIAMETER & mensaje,long &tiempoConsumidoAntesConmutacion,long &tiempoConsumidoDespuesConmutacion,long &tiempoConsumidoSinConmutacion,bool &hayUSUantes, bool &hayUSUdespues);
257 //
258 //   // nos devuelve el volumen que viene en el mensaje diameter (antes, despues de la conmutacion y el valor cuando no ha  habido conmutacion)
259 //   // Le pasamos el tipo volumen que queremos  ( ambos,downlink,uplink)
260 //   // en tipoVol, se indica de que   AVP leemos las unidades ( Input_Octets, Output-Octets o TotalOctets )
261 //   //static void dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volAntesConmutacion,long &volDespuesConmutacion,long &volConsumidoSinConmutacion);
262 //   // Devuelve FALSE si ha habido algun error
263 //   static bool dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volUpAntesConmutacion,long &volUpDespuesConmutacion,
264 //                  long &volDownAntesConmutacion,long &volDownDespuesConmutacion,long &volUp,long &volDown,bool &errorTariffChange);
265 //   static bool dameVolumConsumido(const InfoDIAMETER & mensaje,int tipoVol,long &volUpAntesConmutacion,long &volUpDespuesConmutacion,
266 //                  long &volDownAntesConmutacion,long &volDownDespuesConmutacion,long &volUp,long &volDown,bool &errorTariffChange,
267 //                  bool &hayUSUantes, bool &hayUSUdespues);
268 //
269 //
270 //   bool getConsumedTime(int &beforeSwitch, int &afterSwitch, int &withoutSwitch) const ;
271 //   bool getConsumedVolume(int volumeType, int &upBeforeSwitch, int &upAfterSwitch, int &downBeforeSwitch, int &downAfterSwitch, int &upWithoutSwitch, int &downWithoutSwitch, bool &tariffChangeError) const ;
272 //
273
274
275
276
277
278 };
279
280 }
281 }
282 }
283 }
284
285 #endif