I'm trying to explore the C++ haystack implementation by jasondbriggs and have not understood the flow of the code and how the dictionary works, can someone explain the working?
Radu RacariuFri 8 Dec 2017
Hello,
you can check out the docs for a high level description:
On the specific of the dictionary - it is just a wrapper around boost::ptr_map (think std::map for pointers).
Abhay NayakMon 11 Dec 2017
I'm trying to update the data in the dictionary after the server starts but i'm not able to do it. it shows "Error: Invalid name start char"
Radu RacariuMon 11 Dec 2017
The error is not specific to the Dict - it is from the zinc parser, and it appears that the zinc encoding for some id is not correct (the beginning of the id is not a lower case char).
When you say you want to update the Dict, are you loading a zinc file?
Actually, my aim is to keep updating sensor values and get it on client request even after the haystack server starts.
I've connected a temperature sensor and I'm reading it from port and passing it to this code. I passed the values through add_site() in class TestProj before starting the server (calling add_site() in constructor in TestProj.cpp) and got same values on client request.
But then I wanted to keep updating values even after the server started, so I modified the code to setup a timer logic using signals every 5 seconds in the haystack_server.cpp code
haystack::TestProj proj;
// set-up a HTTPServer instance
HTTPServer srv(new HaystackRequestHandlerFactory(proj), svs, pParams);
// start the HTTPServer
srv.start();
std::cout << "Haystack++ HTTP Demo Server running... \n";
//modified part starts
signal(SIGALRM , proj.signalhandler);
alarm(5);
//modified part ends
// wait for CTRL-C or kill
waitForTerminationRequest();
// Stop the HTTPServer
srv.stop();
signal_handler() function calls the add_site() in it (both function in TestProj.cpp)
On client request it gives "Error: Invalid name start char" which means that the object itself was not created in signal_handler
I know I'm going in too much details but can you help me out here? Or refer me something that can give updated values on client side.
Abhay NayakThu 14 Dec 2017
The changes I made need runtime linking in cmake files but I'm not able to do it. Can you assist me there?
Radu RacariuWed 20 Dec 2017
I'm not sure what are you trying to do there, but for sure using signal handlers is a no go, they are very limited on what they can do, see http://en.cppreference.com/w/cpp/utility/program/signal the Signal handler section and the limitations.
You should reconsider your design.
In cmake, change the linker flags variable and add your definitions.
Abhay Nayak Fri 8 Dec 2017
I'm trying to explore the C++ haystack implementation by jasondbriggs and have not understood the flow of the code and how the dictionary works, can someone explain the working?
Radu Racariu Fri 8 Dec 2017
Hello,
you can check out the docs for a high level description:
https://bitbucket.org/jasondbriggs/haystack-cpp/wiki/Home
There is also a pdf with the code docs https://bytebucket.org/jasondbriggs/haystack-cpp/wiki/refman.pdf?rev=2d017578f1ca52be3c8c1fa4d40dbd2f97c07a83
On the specific of the dictionary - it is just a wrapper around boost::ptr_map (think std::map for pointers).
Abhay Nayak Mon 11 Dec 2017
I'm trying to update the data in the dictionary after the server starts but i'm not able to do it. it shows "Error: Invalid name start char"
Radu Racariu Mon 11 Dec 2017
The error is not specific to the Dict - it is from the zinc parser, and it appears that the zinc encoding for some id is not correct (the beginning of the id is not a lower case char).
When you say you want to update the Dict, are you loading a zinc file?
Saying this, I think you need to look at the unit tests folder (https://bitbucket.org/jasondbriggs/haystack-cpp/src/master/tests/) to get an idea on how various object can be called.
Abhay Nayak Wed 13 Dec 2017
Actually, my aim is to keep updating sensor values and get it on client request even after the haystack server starts.
I've connected a temperature sensor and I'm reading it from port and passing it to this code. I passed the values through add_site() in class TestProj before starting the server (calling add_site() in constructor in TestProj.cpp) and got same values on client request.
But then I wanted to keep updating values even after the server started, so I modified the code to setup a timer logic using signals every 5 seconds in the haystack_server.cpp code
signal_handler() function calls the add_site() in it (both function in TestProj.cpp)
On client request it gives "Error: Invalid name start char" which means that the object itself was not created in signal_handler
I know I'm going in too much details but can you help me out here? Or refer me something that can give updated values on client side.
Abhay Nayak Thu 14 Dec 2017
The changes I made need runtime linking in cmake files but I'm not able to do it. Can you assist me there?
Radu Racariu Wed 20 Dec 2017
I'm not sure what are you trying to do there, but for sure using signal handlers is a no go, they are very limited on what they can do, see http://en.cppreference.com/w/cpp/utility/program/signal the
Signal handler
section and the limitations.You should reconsider your design.
In cmake, change the linker flags variable and add your definitions.