89 lines
2.0 KiB
Markdown
Raw Normal View History

2026-02-13 12:36:06 +01:00
# Examples for liblogosdelivery
2026-02-05 16:23:34 +01:00
This directory contains example programs demonstrating the usage of the Logos Messaging API (LMAPI) library.
## Building the Examples
### Prerequisites
2026-02-13 12:36:06 +01:00
1. Build the liblogosdelivery library first:
2026-02-05 16:23:34 +01:00
```bash
cd /path/to/logos-messaging-nim
2026-02-13 12:36:06 +01:00
make liblogosdelivery
2026-02-05 16:23:34 +01:00
```
2026-02-13 12:36:06 +01:00
2. The library will be available in `build/liblogosdelivery.so` (or `.dylib` on macOS, `.dll` on Windows)
2026-02-05 16:23:34 +01:00
2026-02-13 12:36:06 +01:00
### Compile the liblogosdelivery Example
2026-02-05 16:23:34 +01:00
#### On Linux/macOS:
```bash
# Shared library
2026-02-13 11:59:42 +01:00
gcc -o liblogosdelivery_example liblogosdelivery_example.c -I.. -L../../build -llmapi -Wl,-rpath,../../build
2026-02-05 16:23:34 +01:00
# Static library (if built with STATIC=1)
2026-02-13 12:36:06 +01:00
gcc -o liblogosdelivery_example liblogosdelivery_example.c -I.. ../../build/liblogosdelivery.a -lpthread -lm -ldl
2026-02-05 16:23:34 +01:00
```
#### On macOS:
```bash
2026-02-13 11:59:42 +01:00
gcc -o liblogosdelivery_example liblogosdelivery_example.c -I.. -L../../build -llmapi
2026-02-05 16:23:34 +01:00
```
#### On Windows (MinGW):
```bash
2026-02-13 11:59:42 +01:00
gcc -o liblogosdelivery_example.exe liblogosdelivery_example.c -I.. -L../../build -llmapi -lws2_32
2026-02-05 16:23:34 +01:00
```
## Running the Examples
2026-02-13 12:36:06 +01:00
### liblogosdelivery Example
2026-02-05 16:23:34 +01:00
```bash
2026-02-13 11:59:42 +01:00
./liblogosdelivery_example
2026-02-05 16:23:34 +01:00
```
This example demonstrates:
1. Creating a node with configuration
2. Starting the node
3. Subscribing to a content topic
4. Sending a message
5. Unsubscribing from the topic
6. Stopping and destroying the node
### Expected Output
```
=== Logos Messaging API (LMAPI) Example ===
1. Creating node...
[create_node] Success
2. Starting node...
[start_node] Success
3. Subscribing to content topic...
[subscribe] Success
4. Sending a message...
[send] Success: <request-id>
5. Unsubscribing from content topic...
[unsubscribe] Success
6. Stopping node...
[stop_node] Success
7. Destroying context...
[destroy] Success
=== Example completed ===
```
## Notes
- The examples use simple synchronous callbacks with sleep() for demonstration
- In production code, you should use proper async patterns
- Error handling in these examples is basic - production code should be more robust
- The payload in messages must be base64-encoded