Project demonstrating the use of Homegear's Inter-process Communication Interface
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Homegear IPC Example

This example project demonstrates how to access Homegear's IPC (= Inter-process Communication) interface. It registers two RPC methods in Homegear (exampleTest1() and exampleTest2()). exampleTest1() prints a line to the terminal and returns a string containing the current timestamp. exampleTest2() expects a string as parameter, also prints a line to the terminal and returns the length of the string.

Before starting, either compile libhomegear-ipc or on Debian, Raspbian or Ubuntu install it with:

apt install libhomegear-ipc

To compile, just execute:


To test, you can call the newly registerd RPC methods from the shell:

homegear -e rc 'print_v($hg->exampleTest1());'
homegear -e rc 'print_v($hg->exampleTest2("Hello"));'

All RPC methods known by Homegear can be called by executing invoke(). The signature is:

Ipc::PVariable invoke(std::string methodName, Ipc::PArray parameters);

The first parameter is the name of the RPC method (e. g. getValue()). The second parameter is a vector of Ipc::PVariable (= a std::shared_ptr to Ipc::Variable). Ipc::Variable is a class which can contain values of any type. The usage should be self-explaining.

For example to create the parameters array for getValue(12, 1, "STATE"), call:

Ipc::PArray parameters = std::make_shared<Ipc::Array>();

To avoid copy operations, we reserve space for 3 elements.

Now we add the parameters (peer ID, channel and variable name):


Call invoke() and print out the result:

Ipc::PVariable result = invoke("getValue", parameters);
std::cout << "Result: " << result->integerValue << std::endl;