Giter VIP home page Giter VIP logo

homegear-ipc-example's Introduction

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:

./makeDebug.sh

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>();
parameters->reserve(3);

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

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

parameters->push_back(std::make_shared<Ipc::Variable>(12));
parameters->push_back(std::make_shared<Ipc::Variable>(1));
parameters->push_back(std::make_shared<Ipc::Variable>("HUMIDITY"));

Call invoke() and print out the result:

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

homegear-ipc-example's People

Contributors

hfedcba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.