]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/net/cellular/CellularModem/ussd/USSDInterface.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / net / cellular / CellularModem / ussd / USSDInterface.h
1 /* USSDInterface.h */
2 /* Copyright (C) 2012 mbed.org, MIT License
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5  * and associated documentation files (the "Software"), to deal in the Software without restriction,
6  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all copies or
11  * substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18  */
19
20 #ifndef USSDINTERFACE_H_
21 #define USSDINTERFACE_H_
22
23 #include "core/fwk.h"
24
25 #include "rtos.h"
26
27 #include "at/ATCommandsInterface.h"
28
29 /** Component to send/receive Unstructured Supplementary Service Data (USSD)
30  *
31  */
32 class USSDInterface : protected IATCommandsProcessor, IATEventsHandler
33 {
34 public:
35   /** Create USSDInterface instance
36      @param pIf Pointer to the ATCommandsInterface instance to use
37    */
38   USSDInterface(ATCommandsInterface* pIf);
39
40   /** Initialize interface
41    Configure USSD commands & register for USSD-related unsolicited result codes
42   */
43   int init();
44
45   /** Send a USSD command & wait for its result
46     @param command The command to send
47     @param result Buffer in which to store the result
48     @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
49     @return 0 on success, error code on failure
50   */
51   int send(const char* command, char* result, size_t maxLength);
52
53 protected:
54   //IATCommandsProcessor, needed for implementations of 3GGP standard < r06
55   virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
56   virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
57   
58   //IATEventsHandler, needed for implementations of 3GGP standard >= r06
59   virtual bool isATCodeHandled(const char* atCode); //Is this AT code handled
60   virtual void onDispatchStart();
61   virtual void onDispatchStop();
62   virtual char* getEventsEnableCommand();
63   virtual char* getEventsDisableCommand();
64   virtual void onEvent(const char* atCode, const char* evt);
65
66 private:
67   void processResult(const char* data);
68
69   ATCommandsInterface* m_pIf;
70   Mutex m_responseMtx; //To protect concurrent accesses btw the user's thread and the AT thread
71   Semaphore m_responseSphre;
72
73   //Result
74   volatile char* m_result;
75   volatile size_t m_maxResultLength;
76
77 };
78
79
80 #endif /* USSDINTERFACE_H_ */