> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/madk__pp__protocol_8h_source.md).

# madk\_pp\_protocol.h

[Go to the documentation of this file.](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/madk__pp__protocol_8h.md)

```cpp
 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 #include "_logf.h"
 13 
 15 struct mADK_PP_Prot_Loader;
 17 struct ProtStatus;
 18 struct ConnectInfo;
 19 struct TcpInfo;
 20 struct UdsInfo;
 21 
 24 class mADK_PP_Prot
 25 {
 26  public:
 27 
 28  enum ProtocolState
 29  {
 30  PS_Stopped = 0,
 31  PS_Running = 1,
 32  PS_Aborted = 2
 33  };
 34 
 35  enum AbortState
 36  {
 37  AS_NotAborted = 0,
 38  AS_AbortIdle = 1,
 39  AS_ConnectionLost = 2
 42  };
 43 
 44  enum ConnectionType
 45  {
 46  CT_None = 0,
 47  CT_Tcp = 1,
 48  CT_Uds = 2,
 49  CT_Udp = 3,
 50  CT_Ssl = 4,
 51  CT_UsbSerial = 5,
 52  CT_Bluetooth = 6
 53  };
 54 
 55  private:
 56 #ifndef _STM32 // no SDI protocol thread on Titus
 57  pthread_t proto_thread;
 58 #endif
 59  pthread_mutex_t mutex;
 60  pthread_cond_t cond;
 61  std::vector<unsigned char> cmdbuf;
 62  char prot_type;
 64  unsigned msg_id;
 65  unsigned msg_id_payment;
 66  unsigned msg_id_nested;
 67  enum ProtocolState prot_state;
 68  bool cmd_active;
 69  bool nested_cmd;
 70  enum AbortState aborted;
 71  unsigned cmd_counter;
 73  struct mADK_PP_Prot_Loader *lib;
 77  enum CommandType
 78  {
 79  Cmd_Any = 0,
 80  Cmd_Abort = 1,
 81  Cmd_LockPayment = 2,
 83  Cmd_ResetLink = 3,
 86  Cmd_Check4Update = 4,
 87  Cmd_ExtButton = 5,
 88  Cmd_EmvCbResponse = 6,
 89  Cmd_CtrlCbResponse = 7,
 90  Cmd_TrgrCbResponse = 8,
 91  Cmd_PaymentNotificationCb = 9,
 92  Cmd_RegisterAdkLogCb = 10
 94  };
 96  enum RequestType
 97  {
 98  Request_None = 0,
 99  Request_EMV = 1,
 100  Request_Ctrl = 2,
 101  Request_Trgr = 3
 102  };
 103  RequestType req_type;
 104  bool recovery_mode;
 105  bool busy;
 106  bool cancelled;
 107  bool unlock_payment_pending;
 110  void *main_handle;
 117  void *busy_handle;
 120  LibLogHandle sdiComLogHandle;
 122 #ifdef _STM32
 123  void *log_handle;
 126  char log_prot_type;
 128  unsigned log_msg_id;
 129  std::vector<unsigned char> log_chunk_buf;
 137  void registerAdkLogCallback(void *handle, char protType, unsigned msgId, int reg_opts);
 142  void unregisterAdkLogCallback(void *handle);
 143 #endif
 144  static mADK_PP_Prot *obj; // singleton
 145 
 146  // disable calling copy constructor and assignment operator
 147  mADK_PP_Prot(const mADK_PP_Prot &);
 148  void operator=(const mADK_PP_Prot &);
 149 #if __cplusplus >= 201103L // since C++11 also forbid usage of move
 150  mADK_PP_Prot(const mADK_PP_Prot&&);
 151  mADK_PP_Prot& operator=(mADK_PP_Prot&&);
 152 #endif
 153 
 154  // disable constructor and force caller to use getInstance()
 155  mADK_PP_Prot();
 158  virtual ~mADK_PP_Prot();
 159 
 162  static void *run(void *data);
 163 
 170  static enum CommandType getCommandType(const unsigned char *cmd, unsigned size);
 171 
 176  static bool isCallbackResponse(const enum CommandType cmd);
 177 
 185  bool _poll(int timeout_msec);
 186 
 195  bool _receive(std::vector<unsigned char> &cmd, int timeout_msec);
 196 
 203  bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const;
 204 
 208  enum ConnectionType _get_connection_type(void *handle);
 209  public:
 210 
 213  static mADK_PP_Prot *getInstance();
 214 
 218  inline struct mADK_PP_Prot_Loader *loader()
 219  {
 220  return lib;
 221  }
 222 
 229  bool poll(int timeout_msec = -1);
 230 
 238  bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1);
 239 
 248  bool abort();
 249 
 261  bool send(const unsigned char *cmd, unsigned size);
 262 
 264  inline bool send(const std::vector<unsigned char> &cmd)
 265  {
 266  return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());
 267  }
 268 
 280  bool command(const unsigned char *cmd, unsigned size);
 281 
 298  bool request(const unsigned char *cmd, unsigned size);
 299 
 301  inline bool request(const std::vector<unsigned char> &cmd)
 302  {
 303  return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());
 304  }
 305 
 318  bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1);
 319 
 343  bool set_busy(bool flag, bool cmd_ctx = true);
 344 
 348  bool loadAcl();
 349 
 351  enum CMDActiveType
 352  {
 353  CMD_None = 0,
 354  CMD_Active = 1,
 355  CMD_Nested = 2
 356  };
 360  inline enum CMDActiveType command_active() const
 361  {
 362  if (cmd_active)
 363  {
 364  if (nested_cmd)
 365  {
 366  return CMD_Nested;
 367  }
 368 
 369  return CMD_Active;
 370  }
 371 
 372  return CMD_None;
 373  }
 374 
 378  bool start();
 379 
 383  void stop();
 384 
 387  void setRecoveryMode(bool on_off);
 388 
 391  inline enum ProtocolState get_protocol_state() const
 392  {
 393  return prot_state;
 394  }
 395 
 401  inline bool connected() const
 402  {
 403  return !!get_handle();
 404  }
 405 
 410  inline bool check_abort() const
 411  {
 412  return cancelled;
 413  }
 414 
 423  void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId);
 424 
 425 #ifdef _STM32
 426 
 431  void adkLogForwarder(const unsigned char *logdata, int len);
 432 #endif
 433 
 435  bool get_status(struct ProtStatus *status) const;
 436 
 438  bool get_connection_info(struct ConnectInfo *info) const;
 439 
 441  void free_connection_info(struct ConnectInfo *info) const;
 442 
 444  void set_com_profile(const char *file) const;
 445 
 450  enum ConnectionType get_connection_type();
 451 
 456  bool trusted_connection();
 457 
 464  bool get_tcp_info(struct TcpInfo *info);
 465 
 472  bool get_uds_info(struct UdsInfo *info);
 473 
 478  void *get_handle() const;
 479 
 482  char get_protocol_type() const;
 483 
 498  bool isConnectionThread() const;
 499 
 507  bool isMainConnectionThread() const;
 508 
 515  int select(int comInterfaces, char **ComFileName);
 516 
 519  void reset();
 520 };
 521 
 524 class mADK_PP_ProtBusyLock
 525 {
 526  mADK_PP_Prot *m_proto;
 527  bool m_locked;
 528 
 529  // disable copy constructor and assign operator
 530  mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&);
 531  mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&);
 532 #if __cplusplus >= 201103L // since C++11 also forbid usage of move
 533  mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&);
 534  mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&);
 535 #endif
 536 
 537  public:
 542  mADK_PP_ProtBusyLock(bool cmd_ctx = true)
 543  {
 544  m_proto = mADK_PP_Prot::getInstance();
 545  m_locked = m_proto->set_busy(true, cmd_ctx);
 546  }
 548  virtual ~mADK_PP_ProtBusyLock()
 549  {
 550  unlock();
 551  }
 554  void unlock()
 555  {
 556  if (m_locked)
 557  {
 558  m_proto->set_busy(false);
 559  m_locked = false;
 560  }
 561  }
 564  bool locked() const
 565  {
 566  return m_locked;
 567  }
 568 };
 569 
 570 #endif
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/madk__pp__protocol_8h_source.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
