Re: [Cppcms-users] Server
Brought to you by:
artyom-beilis
|
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
|