Thread: [Cppcms-users] Server
Brought to you by:
artyom-beilis
From: eric m. <mid...@gm...> - 2016-01-02 11:32:58
Attachments:
ticker.cpp
|
Hi, I'm developing a robot that is controlled via the browser by issuing commands. Apart from the cppcms applications that are started from main, the server has an additional thread for controlling the motors: robotThread While the robotThread is acting on a command I like it to report progress back to the browser so that I can follow what exactly it is doing. The idea is to use ticker-example http://blog.cppcms.com/post/107 and replace the timed updates by something like a boost::signals2 slot so that progress in the robotThread can be reported to the cppcms comet application that can report it to the browser. Enclosed is the sourcecode of a small testprogram based on the ticker example. It does not compile because of an error: use of deleted function ‘ticker::ticker(const ticker&). I can't find a way to connect the cppcms comet application to the signal. Do you have any idea how to do this or any other way to use the cppcms comet application as a proxy between server and webclient? Kind regards, Eric |
From: Artyom B. <art...@gm...> - 2016-01-02 17:01:39
|
Hi, You have two issues: 1st of all your code does not compile because sig.connect tries to copy the ticker class which isn't something you actually want. And in general if you already using boost::signals2 you should also use its automatic disconnection handling. So first change would be boost::signals2::scoped_connection conn; void connectSlot() { conn = std::move(sig.connect([this](double v) { this->on_new_value(v); })); } Now the second issue is that you should be aware of the fact that the robot thread and application thread are different so what you need to do is to use service().post(handler) to post code execution to the main event loop of the cppcms: void on_new_value(double v) { service().post([=]() { // post for execution in relevant thread this->handle(v); }); } // now actual work void handle(double new_one) { cout << "SLOT CALLED" << endl; counter_++; price_ = new_one; for(auto waiter : waiters_) { async_send(waiter); } waiters_.clear(); } Regards, Artyom On Sat, Jan 2, 2016 at 1:32 PM, eric middelkoop <mid...@gm...> wrote: > Hi, > > I'm developing a robot that is controlled via the browser by issuing > commands. > > Apart from the cppcms applications that are started from main, the server > has an additional thread for controlling the motors: robotThread > > While the robotThread is acting on a command I like it to report progress > back to the browser so that I can follow what exactly it is doing. > > The idea is to use ticker-example http://blog.cppcms.com/post/107 and > replace the timed updates by something like a boost::signals2 slot so that > progress in the robotThread can be reported to the cppcms comet application > that can report it to the browser. > > Enclosed is the sourcecode of a small testprogram based on the ticker > example. It does not compile because of an error: use of deleted function > ‘ticker::ticker(const ticker&). I can't find a way to connect the cppcms > comet application to the signal. > > Do you have any idea how to do this or any other way to use the cppcms comet > application as a proxy between server and webclient? > > Kind regards, > Eric > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: eric m. <mid...@gm...> - 2016-01-03 08:44:56
|
Hi Artyom, Thank you for your quick response. That really did the trick! I have two other questions: 1) How does the "id" work under water? Is it that I just always need the id and can add any data underneath it? 2) How does cppcms handle exceptions? For instance I have an Ajax-call to a method and that method throws, but it seems that the exception is swallowed somewhere as it does not appear anywhere? Kind regards, Eric Ps. A nice comet-example with signals2 might be applicable for others as well. On Sat, Jan 2, 2016 at 12:01 PM, Artyom Beilis <art...@gm...> wrote: > Hi, > > You have two issues: > > 1st of all your code does not compile because sig.connect tries to > copy the ticker class which isn't something you actually want. And in > general if you already using boost::signals2 you should also use its > automatic disconnection handling. So first change would be > > boost::signals2::scoped_connection conn; > > void connectSlot() > { > conn = std::move(sig.connect([this](double v) { > this->on_new_value(v); > })); > } > > Now the second issue is that you should be aware of the fact that the > robot thread and application thread are different so what you need to > do is to use service().post(handler) to post code execution to the > main event loop of the cppcms: > > void on_new_value(double v) > { > service().post([=]() { // post for execution in relevant thread > this->handle(v); > }); > } > // now actual work > void handle(double new_one) > { > cout << "SLOT CALLED" << endl; > counter_++; > price_ = new_one; > for(auto waiter : waiters_) { > async_send(waiter); > } > waiters_.clear(); > } > > > Regards, > Artyom > > > On Sat, Jan 2, 2016 at 1:32 PM, eric middelkoop > <mid...@gm...> wrote: > > Hi, > > > > I'm developing a robot that is controlled via the browser by issuing > > commands. > > > > Apart from the cppcms applications that are started from main, the server > > has an additional thread for controlling the motors: robotThread > > > > While the robotThread is acting on a command I like it to report progress > > back to the browser so that I can follow what exactly it is doing. > > > > The idea is to use ticker-example http://blog.cppcms.com/post/107 and > > replace the timed updates by something like a boost::signals2 slot so > that > > progress in the robotThread can be reported to the cppcms comet > application > > that can report it to the browser. > > > > Enclosed is the sourcecode of a small testprogram based on the ticker > > example. It does not compile because of an error: use of deleted function > > ‘ticker::ticker(const ticker&). I can't find a way to connect the cppcms > > comet application to the signal. > > > > Do you have any idea how to do this or any other way to use the cppcms > comet > > application as a proxy between server and webclient? > > > > Kind regards, > > Eric > > > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > -- Groetjes, Eric http://www.lightandmagicphotography.nl http://www.lightandmagicphotography.com |
From: Artyom B. <art...@gm...> - 2016-01-03 11:27:59
|
On Sun, Jan 3, 2016 at 10:44 AM, eric middelkoop <mid...@gm...> wrote: > Hi Artyom, > > Thank you for your quick response. That really did the trick! > > I have two other questions: > 1) How does the "id" work under water? Is it that I just always need the id > and can add any data underneath it? Take a look on description of Server Sent Events: http://www.w3.org/TR/eventsource/ It is required for the client to automatic synchronization with the server in case of disconnect. > 2) How does cppcms handle exceptions? For instance I have an Ajax-call to a > method and that method throws, but it seems that the exception is swallowed > somewhere as it does not appear anywhere? > Depends... 1. If the exception is thrown from cppcms::application::main (i.e. request handler) it would be wrtten into log (of course if logging enabled) 2. If it is thrown in the event loop thread - outside of ordinary request it would propagate all the way outside cppcms::service::run() > > Ps. A nice comet-example with signals2 might be applicable for others as > well. That is what mailing list for :-) I think boost::signal(2) is good for "broadcasting" a signal to multiple listeners it is less interesting in case of one event sent to a specific target I'd just > -- > Groetjes, > Eric > Regards. Artyom |
From: eric m. <mid...@gm...> - 2016-01-03 13:50:28
|
Ok thanks! I will dive into that. Just curious, what would you use instead of signal2 in this case? Kind regards, Eric On Sun, Jan 3, 2016 at 6:27 AM, Artyom Beilis <art...@gm...> wrote: > On Sun, Jan 3, 2016 at 10:44 AM, eric middelkoop > <mid...@gm...> wrote: > > Hi Artyom, > > > > Thank you for your quick response. That really did the trick! > > > > I have two other questions: > > 1) How does the "id" work under water? Is it that I just always need the > id > > and can add any data underneath it? > > Take a look on description of Server Sent Events: > > http://www.w3.org/TR/eventsource/ > > It is required for the client to automatic synchronization with the server > in case of disconnect. > > > 2) How does cppcms handle exceptions? For instance I have an Ajax-call > to a > > method and that method throws, but it seems that the exception is > swallowed > > somewhere as it does not appear anywhere? > > > > Depends... > > 1. If the exception is thrown from cppcms::application::main (i.e. > request handler) > it would be wrtten into log (of course if logging enabled) > 2. If it is thrown in the event loop thread - outside of ordinary > request it would propagate > all the way outside cppcms::service::run() > > > > > Ps. A nice comet-example with signals2 might be applicable for others as > > well. > > That is what mailing list for :-) > > I think boost::signal(2) is good for "broadcasting" a signal to > multiple listeners > it is less interesting in case of one event sent to a specific target I'd > just > > > -- > > Groetjes, > > Eric > > > > Regards. > Artyom > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > -- Groetjes, Eric http://www.lightandmagicphotography.nl http://www.lightandmagicphotography.com |