# Using the Library

## General Overview

Using the Binho Mission Control C++ SDK library typically involves a series of steps to communicate with a target connected to the host adapter, execute commands and handle responses. Command requests and responses follow the Bridge API v1, which can be found at [Bridge API v1 Documentation](https://support.binho.io/bridge-supernova-api-1.0).

Bellow is a high-level overview based on the provided example applications:

### 1. **Include Necessary Headers**

Include the necessary headers to access library's functionality:

```
#include "CommandDispatcher.h"
#include <iostream>
```

### 2. **Define Response Handler**

Define a function to handle responses from the commands sent to the target adapter. This function is responsible for displaying relevant information about the command's execution.

```
void printCommandResponse(const CommandResponse& cr, const std::string& action);
```

### 3. **Initialize the Dispatcher**

Create an instance of `CommandDispatcher` and specify the name of the target host adapter:

```
CommandDispatcher dispatcher("BinhoNova");   // For connecting with the Binho Nova host adapter
CommandDispatcher dispatcher("BinhoSupernova");   // For connecting with the Binho Supernova host adapter
```

**Note**: The argument passed to the `CommandDispatcher` initializer is the name of the target host adapter.

### 4. **Start the Dispatcher**

Before sending any commands, start the dispatcher:

```
dispatcher.start();
```

### 5. **Invoke Commands**

With the dispatcher running, invoke commands as needed:

* Synchronous Commands (waits for the command to finish before moving on):

```
dispatcher.invokeCommandSync("transaction_id", "command_name", command_params, response_handler);
```

* Asynchronous Commands (doesn't wait for the command to finish):

```
dispatcher.invokeCommand("transaction_id", "command_name", command_params);
```

### 6. **Wait for All Commands to Finish (Recommended)**

To ensure all issued commands are finished before proceeding:

```
dispatcher.waitForAllCommands();
```

### 7. **Stop the Dispatcher**

Once all tasks are completed, stop the dispatcher:

```
dispatcher.stop();
```


---

# Agent Instructions: 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:

```
GET https://support.binho.io/getting-started/c++-sdk/using-the-library.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
