AidConnect C++ API
💡Note When developing with Aidconnect-SDK C++, the following points need to be noted:
- The header file must be included during compilation, stored at: /usr/local/include/aidlux/aidconnect/aidconnect.hpp
- The library file must be specified during linking, stored at: /usr/local/lib/aidlux/aidconnect/libaidconnect.so
enum struct LogLevel
| Member Variable Name | Type | Default Value | Description |
|---|---|---|---|
| DEBUG | uint8_t | 0 | Debug log level |
| INFO | uint8_t | 1 | Info log level |
| WARNING | uint8_t | 2 | Warning log level |
| ERROR | uint8_t | 3 | Error log level |
Class Aidkv
A shared memory communication class implemented based on C++.
get_library_version()
| API | get_library_version |
| Description | Used to obtain version-related information of the current Aidconnect. |
| Parameters | void |
| Return | Returns a string containing the version information of the current Aidconnect |
set_log_level()
| API | set_log_level |
| Description | Sets the current minimum log level, and outputs log data with levels greater than or equal to this level. By default, logs of WARNING level and above are printed. |
| Parameters | log_level: Value of the enumeration type LogLevel |
| Return | Returns 0 by default |
init()
As the name implies, this function implements relevant initialization work.
| API | init |
| Description | Completes relevant initialization work |
| Parameters | void |
| Return | 0 indicates the initialization operation is successful; a non-0 value indicates failure |
int status = aidconnect.init();
if(EXIT_SUCCESS != status){
printf("aidconnect.init failed !\n");
return EXIT_FAILURE;
}aidconnect_with_name()
This function is used to specify which shared memory block we need to use. It should be noted that this interface only checks whether a shared memory block exists and does not create new shared memory (the creation of shared memory is implemented by the Android-side interface).
| API | aidconnect_with_name |
| Description | Specifies the use of a specific shared memory block |
| Parameters | block_id: ID string of a specific shared memory block |
| Return | 0 indicates the operation is successful; a non-0 value indicates failure |
status = aidconnect.aidconnect_with_name("we");
if(EXIT_SUCCESS != status){
printf("aidconnect.aidkv_with_id failed !\n");
return EXIT_FAILURE;
}set_bytes()
This function writes byte data to the corresponding shared memory.
| API | set_bytes |
| Description | Writes byte data to the corresponding shared memory |
| Parameters | buffer: Memory address storing the data |
| len: Byte length of the data to be written | |
| Return | 0 indicates the write operation is successful; a non-0 value indicates failure |
status = aidconnect.set_bytes(buffer, sizeof(buffer));
if(EXIT_SUCCESS != status){
printf("aidconnect.set_bytes failed !\n");
return EXIT_FAILURE;
}get_bytes()
This function reads the required byte data from the corresponding shared memory.
| API | get_bytes |
| Description | Reads the required byte data from the corresponding shared memory |
| Parameters | buffer: Address of a pointer variable; the function copies data to this pointer variable address |
| len: Byte length of the data to be obtained | |
| Return | 0 indicates the read operation is successful; a non-0 value indicates failure |
| Note | Before using this interface, developers need to allocate the required memory by themselves to store the data obtained from the shared memory |
status = aidconnect.get_bytes(&result, &length);
if(EXIT_SUCCESS != status){
printf("aidconnect.get_bytes failed !\n");
return EXIT_FAILURE;
}AidConnect C++ Sample Program
💡Note
The AidConnect-SDK sample program is installed with the software package:
- C++ sample program path: /usr/local/share/aidconnect/examples/cpp/
The C++ sample program here roughly includes the following parts:
Initialization
Initialization is a mandatory step, which will complete prerequisites such as configuration parsing.
Aidlux::AidConnect aidconnect;
int status = aidconnect.init();
if(EXIT_SUCCESS != status){
printf("aidconnect.init failed !\n");
return EXIT_FAILURE;
}Associate a Specific Shared Memory Block
To achieve data interaction, the entities that need to exchange data must focus on the same shared memory block and perform read/write operations on it.
status = aidconnect.aidconnect_with_name("your_shm_name");
if(EXIT_SUCCESS != status){
printf("aidconnect.aidconnect_with_name failed !\n");
return EXIT_FAILURE;
}Read and Write Data
The essence of data interaction is the read/write operation of the same data. Here is an example of a write operation:
char buffer[] = "Hello Cpp";
status = aidconnect.set_bytes(buffer, sizeof(buffer));
if(EXIT_SUCCESS != status){
printf("aidconnect.set_bytes failed !\n");
return EXIT_FAILURE;
}Similarly, the read operation follows the same steps: initialize first, then associate the shared memory block, and finally call the data reading interface to obtain data.