Skip to main content

Application Development Kit (Version 4.7)


madk_pp_protocol.h

Last updated: 25-Feb-2025
Go to the documentation of this file.
    1 /*****************************************************************************    2  *  Company:     Verifone    3  *  Author:      GSS R&D Germany    4  *  Content:     SDI-Server    5  ****************************************************************************/    6 #ifndef _MADK_PP_PROTOCOL_H_    7 #define _MADK_PP_PROTOCOL_H_    8      9 #include <vector>   10 #include <string>   11 #include <pthread.h>   12     14 struct mADK_PP_Prot_Loader;   16 struct ProtStatus;   17 struct ConnectInfo;   18 struct TcpInfo;   19 struct UdsInfo;   20     23 class mADK_PP_Prot   24 {   25   public:   26     27     enum ProtocolState   28     {   29       PS_Stopped = 0,    30       PS_Running = 1,    31       PS_Aborted = 2     32     };   33     34     enum AbortState   35     {   36       AS_NotAborted = 0,        37       AS_AbortIdle = 1,         38       AS_ConnectionLost = 2     41     };   42     43   private:   44     pthread_t proto_thread;   45     pthread_mutex_t mutex;   46     pthread_cond_t cond;   47     std::vector<unsigned char> cmdbuf;   48     char prot_type;     50     unsigned msg_id;    51     unsigned msg_id_payment;    52     unsigned msg_id_nested;     53     enum ProtocolState prot_state;    54     bool cmd_active;    55     bool nested_cmd;    56     enum AbortState aborted;     57     unsigned cmd_counter;    59     struct mADK_PP_Prot_Loader *lib;    63     enum CommandType   64     {   65       Cmd_Any                   = 0,    66       Cmd_Abort                 = 1,    67       Cmd_LockPayment           = 2,    69       Cmd_ResetLink             = 3,    72       Cmd_Check4Update          = 4,    73       Cmd_ExtButton             = 5,    74       Cmd_EmvCbResponse         = 6,    75       Cmd_CtrlCbResponse        = 7,    76       Cmd_TrgrCbResponse        = 8,    77       Cmd_PaymentNotificationCb = 9     78     };   80     enum RequestType   81     {   82       Request_None = 0,     83       Request_EMV  = 1,     84       Request_Ctrl = 2,     85       Request_Trgr = 3      86     };   87     RequestType req_type;    88     bool recovery_mode;    89     bool busy;    90     bool cancelled;    91     bool unlock_payment_pending;    94     void *main_handle;    101     void *busy_handle;   104     static mADK_PP_Prot *obj; // singleton  105    106     // disable calling copy constructor and assignment operator  107     mADK_PP_Prot(const mADK_PP_Prot &);  108     void operator=(const mADK_PP_Prot &);  109 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  110     mADK_PP_Prot(const mADK_PP_Prot&&);  111     mADK_PP_Prot& operator=(mADK_PP_Prot&&);  112 #endif  113    114     // disable constructor and force caller to use getInstance()  115     mADK_PP_Prot();  118     virtual ~mADK_PP_Prot();  119    122     static void *run(void *data);  123    130     static enum CommandType getCommandType(const unsigned char *cmd, unsigned size);  131    136     static bool isCallbackResponse(const enum CommandType cmd);  137    145     bool _poll(int timeout_msec);  146    155     bool _receive(std::vector<unsigned char> &cmd, int timeout_msec);  156    163     bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const;  164    171     int _get_connection_type(void *handle);  172   public:  173    176     static mADK_PP_Prot *getInstance();  177    181     inline struct mADK_PP_Prot_Loader *loader()  182     {  183       return lib;  184     }  185    192     bool poll(int timeout_msec = -1);  193    201     bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1);  202    211     bool abort();  212    224     bool send(const unsigned char *cmd, unsigned size);  225    227     inline bool send(const std::vector<unsigned char> &cmd)  228     {  229       return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  230     }  231    243     bool command(const unsigned char *cmd, unsigned size);  244    261     bool request(const unsigned char *cmd, unsigned size);  262    264     inline bool request(const std::vector<unsigned char> &cmd)  265     {  266       return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  267     }  268    281     bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1);  282    306     bool set_busy(bool flag, bool cmd_ctx = true);  307    311     bool loadAcl();  312    314     enum CMDActiveType  315     {  316       CMD_None   = 0,   317       CMD_Active = 1,   318       CMD_Nested = 2    319     };  323     inline enum CMDActiveType command_active() const  324     {  325       if (cmd_active)  326       {  327         if (nested_cmd)  328         {  329           return CMD_Nested;  330         }  331    332         return CMD_Active;  333       }  334    335       return CMD_None;  336     }  337    341     bool start();  342    346     void stop();  347    350     void setRecoveryMode(bool on_off);  351    354     inline enum ProtocolState get_protocol_state() const  355     {  356       return prot_state;  357     }  358    364     inline bool connected() const  365     {  366       return !!get_handle();  367     }  368    373     inline bool check_abort() const  374     {  375       return cancelled;  376     }  377    386     void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId);  387    389     bool get_status(struct ProtStatus *status) const;  390    392     bool get_connection_info(struct ConnectInfo *info) const;  393    395     void free_connection_info(struct ConnectInfo *info) const;  396    398     void set_com_profile(const char *file) const;  399    404     bool trusted_connection();  405    412     bool get_tcp_info(struct TcpInfo *info);  413    420     bool get_uds_info(struct UdsInfo *info);  421    426     void *get_handle() const;  427    430     char get_protocol_type() const;  431    446     bool isConnectionThread() const;  447    455     bool isMainConnectionThread() const;  456    463     int select(int comInterfaces, char **ComFileName);  464    467     void reset();  468 };  469    472 class mADK_PP_ProtBusyLock  473 {  474     mADK_PP_Prot *m_proto;  475     bool m_locked;  476    477     // disable copy constructor and assign operator  478     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&);  479     mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&);  480 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  481     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&);  482     mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&);  483 #endif  484    485   public:  490     mADK_PP_ProtBusyLock(bool cmd_ctx = true)  491     {  492       m_proto = mADK_PP_Prot::getInstance();  493       m_locked = m_proto->set_busy(true, cmd_ctx);  494     }  496     virtual ~mADK_PP_ProtBusyLock()  497     {  498       unlock();  499     }  502     void unlock()  503     {  504       if (m_locked)  505       {  506         m_proto->set_busy(false);  507         m_locked = false;  508       }  509     }  512     bool locked() const  513     {  514       return m_locked;  515     }  516 };  517    518 #endif

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo