> 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/readme/examples/mac_demo3_8cpp-example.md).

# mac\_demo3.cpp

```cpp
// SDK
#include <string>
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
// ADK
#include "ipc/jsobject.h"
#include "ipc/notify.h"
#include "log/liblog2.h"
// Constants
#include "constants/notify.h"
const std::string appid("MACDEMO3");
const std::string cp_start_notification("CP_START");
const std::string cp_stop_notification("CP_STOP");
const std::string service_button_notification(SERVICE_BUTTON);
const int SUCCEED = 0;
const int FAIL = -1;
static pthread_mutex_t main_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t main_cond = PTHREAD_COND_INITIALIZER;
static void cb(
   void *data,
   const std::string &from,
   const std::string &to,
   const std::string &notification_id,
   const vfiipc::JSObject &jsobj,
   unsigned flags);
LibLogHandle log_handle;
int main(int argc, char *argv[])
{
   int status = 0;
   for (int i = 0; i < argc; i++)
   {
   LOGF_TRACE(log_handle, "argc[%d] argv[%s]", i, argv[i]);
   }
   log_handle = LOGAPI_INIT(appid.c_str());
   vfiipc::ipcSetAppID(appid);
   status = vfiipc::ipcRegisterNotificationCB(cp_start_notification, cb, NULL, 0);
   if (SUCCEED != status)
   {
   LOGF_ERROR(log_handle, "Can't register cp start callback");
   }
   status = vfiipc::ipcRegisterNotificationCB(cp_stop_notification, cb, NULL, 0);
   if (SUCCEED != status)
   {
   LOGF_ERROR(log_handle, "Can't register cp stop callback");
   }
   status = vfiipc::ipcRegisterNotificationCB(service_button_notification, cb, NULL, 0);
   if (SUCCEED != status)
   {
   LOGF_ERROR(log_handle, "Can't register service button callback");
   }
   bool exit = false;
   while (!exit)
   {
   LOGF_TRACE(log_handle, "main loop");
   pthread_mutex_lock(&main_mutex);
   pthread_cond_wait(&main_cond, &main_mutex);
   pthread_mutex_unlock(&main_mutex);
   }
   return status;
}
static void cb(
   void *,
   const std::string &from,
   const std::string &to,
   const std::string &notification_id,
   const vfiipc::JSObject &jsobj,
   unsigned flags)
{
   LOGF_TRACE(log_handle, "notification from[%s] to[%s] id[%s] flags[%d] json[%s]",
   from.c_str(),
   to.c_str(),
   notification_id.c_str(),
   flags,
   jsobj.dump().c_str());
}
```


---

# 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/readme/examples/mac_demo3_8cpp-example.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.
