Skip to main content

Application Development Kit (Version 4.8)


madk_pp_protocol.h

Last updated: 29-Aug-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 #ifndef _STM32 // no SDI protocol thread on Titus   45     pthread_t proto_thread;   46 #endif   47     pthread_mutex_t mutex;   48     pthread_cond_t cond;   49     std::vector<unsigned char> cmdbuf;   50     char prot_type;     52     unsigned msg_id;    53     unsigned msg_id_payment;    54     unsigned msg_id_nested;     55     enum ProtocolState prot_state;    56     bool cmd_active;    57     bool nested_cmd;    58     enum AbortState aborted;     59     unsigned cmd_counter;    61     struct mADK_PP_Prot_Loader *lib;    65     enum CommandType   66     {   67       Cmd_Any                   = 0,    68       Cmd_Abort                 = 1,    69       Cmd_LockPayment           = 2,    71       Cmd_ResetLink             = 3,    74       Cmd_Check4Update          = 4,    75       Cmd_ExtButton             = 5,    76       Cmd_EmvCbResponse         = 6,    77       Cmd_CtrlCbResponse        = 7,    78       Cmd_TrgrCbResponse        = 8,    79       Cmd_PaymentNotificationCb = 9,    80       Cmd_RegisterAdkLogCb      = 10    82     };   84     enum RequestType   85     {   86       Request_None = 0,     87       Request_EMV  = 1,     88       Request_Ctrl = 2,     89       Request_Trgr = 3      90     };   91     RequestType req_type;    92     bool recovery_mode;    93     bool busy;    94     bool cancelled;    95     bool unlock_payment_pending;    98     void *main_handle;    105     void *busy_handle;   108 #ifdef _STM32  109     void *log_handle;   112     char log_prot_type;   114     unsigned log_msg_id;   115     std::vector<unsigned char> log_chunk_buf;   123     void registerAdkLogCallback(void *handle, char protType, unsigned msgId, int reg_opts);  128     void unregisterAdkLogCallback(void *handle);  129 #endif  130     static mADK_PP_Prot *obj; // singleton  131    132     // disable calling copy constructor and assignment operator  133     mADK_PP_Prot(const mADK_PP_Prot &);  134     void operator=(const mADK_PP_Prot &);  135 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  136     mADK_PP_Prot(const mADK_PP_Prot&&);  137     mADK_PP_Prot& operator=(mADK_PP_Prot&&);  138 #endif  139    140     // disable constructor and force caller to use getInstance()  141     mADK_PP_Prot();  144     virtual ~mADK_PP_Prot();  145    148     static void *run(void *data);  149    156     static enum CommandType getCommandType(const unsigned char *cmd, unsigned size);  157    162     static bool isCallbackResponse(const enum CommandType cmd);  163    171     bool _poll(int timeout_msec);  172    181     bool _receive(std::vector<unsigned char> &cmd, int timeout_msec);  182    189     bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const;  190    197     int _get_connection_type(void *handle);  198   public:  199    202     static mADK_PP_Prot *getInstance();  203    207     inline struct mADK_PP_Prot_Loader *loader()  208     {  209       return lib;  210     }  211    218     bool poll(int timeout_msec = -1);  219    227     bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1);  228    237     bool abort();  238    250     bool send(const unsigned char *cmd, unsigned size);  251    253     inline bool send(const std::vector<unsigned char> &cmd)  254     {  255       return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  256     }  257    269     bool command(const unsigned char *cmd, unsigned size);  270    287     bool request(const unsigned char *cmd, unsigned size);  288    290     inline bool request(const std::vector<unsigned char> &cmd)  291     {  292       return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  293     }  294    307     bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1);  308    332     bool set_busy(bool flag, bool cmd_ctx = true);  333    337     bool loadAcl();  338    340     enum CMDActiveType  341     {  342       CMD_None   = 0,   343       CMD_Active = 1,   344       CMD_Nested = 2    345     };  349     inline enum CMDActiveType command_active() const  350     {  351       if (cmd_active)  352       {  353         if (nested_cmd)  354         {  355           return CMD_Nested;  356         }  357    358         return CMD_Active;  359       }  360    361       return CMD_None;  362     }  363    367     bool start();  368    372     void stop();  373    376     void setRecoveryMode(bool on_off);  377    380     inline enum ProtocolState get_protocol_state() const  381     {  382       return prot_state;  383     }  384    390     inline bool connected() const  391     {  392       return !!get_handle();  393     }  394    399     inline bool check_abort() const  400     {  401       return cancelled;  402     }  403    412     void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId);  413    414 #ifdef _STM32  415    420     void adkLogForwarder(const unsigned char *logdata, int len);  421 #endif  422    424     bool get_status(struct ProtStatus *status) const;  425    427     bool get_connection_info(struct ConnectInfo *info) const;  428    430     void free_connection_info(struct ConnectInfo *info) const;  431    433     void set_com_profile(const char *file) const;  434    439     bool trusted_connection();  440    447     bool get_tcp_info(struct TcpInfo *info);  448    455     bool get_uds_info(struct UdsInfo *info);  456    461     void *get_handle() const;  462    465     char get_protocol_type() const;  466    481     bool isConnectionThread() const;  482    490     bool isMainConnectionThread() const;  491    498     int select(int comInterfaces, char **ComFileName);  499    502     void reset();  503 };  504    507 class mADK_PP_ProtBusyLock  508 {  509     mADK_PP_Prot *m_proto;  510     bool m_locked;  511    512     // disable copy constructor and assign operator  513     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&);  514     mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&);  515 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  516     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&);  517     mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&);  518 #endif  519    520   public:  525     mADK_PP_ProtBusyLock(bool cmd_ctx = true)  526     {  527       m_proto = mADK_PP_Prot::getInstance();  528       m_locked = m_proto->set_busy(true, cmd_ctx);  529     }  531     virtual ~mADK_PP_ProtBusyLock()  532     {  533       unlock();  534     }  537     void unlock()  538     {  539       if (m_locked)  540       {  541         m_proto->set_busy(false);  542         m_locked = false;  543       }  544     }  547     bool locked() const  548     {  549       return m_locked;  550     }  551 };  552    553 #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