See current non-working code:
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WLineEdit>
#include <iostream>
#include <boost/thread.hpp>
#include <list>
using namespace Wt;
using namespace boost;
using namespace std;
class ExampleWidget;
class CometTestApplication;
class CometTestApplication : public WApplication
{
public:
CometTestApplication(const WEnvironment& env);
~CometTestApplication() { l.remove(this); }
ExampleWidget *t;
static list<CometTestApplication *> l;
};
list<CometTestApplication *> CometTestApplication::l;
class ExampleWidget : public WLineEdit
{
boost::thread updater;
static WString value;
public:
void startBigWork()
{
updater = boost::thread(boost::bind(&ExampleWidget::doWork,
this, WApplication::instance(), text()));
yfor ( list<CometTestApplication *>::iterator iter =
CometTestApplication::l.begin(); iter != CometTestApplication::l.end();
++iter )
(*iter)->enableUpdates(true);
}
ExampleWidget()
{
keyWentUp().connect(SLOT(this, ExampleWidget::startBigWork));
}
void doWork(WApplication *app, const WString s)
{
// if you want to update the GUI:
{
WApplication::UpdateLock uiLock = app->getUpdateLock(); // RAII
lock
setText(s + " " + s);
cout << endl << endl << "Session ID=" << wApp->sessionId() << ";
Value=" << text() << endl;
// if using server push, push now the changes to the client
app->triggerUpdate();
}
for ( list<CometTestApplication *>::iterator iter =
CometTestApplication::l.begin(); iter != CometTestApplication::l.end();
++iter )
(*iter)->enableUpdates(false);
}
};
CometTestApplication::CometTestApplication(const WEnvironment& env)
: WApplication(env)
{
t = new ExampleWidget();
root()->addWidget(t);
l.push_back(this);
}
WApplication *createApplication(const WEnvironment& env)
{
return new CometTestApplication(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}
How do I enableUpdates from the event loop of the corresponding session? On
the Ctor?
But that's a bad idea.
How could it possibly know when to push changes ?
>
It's simple, setValue should have another parameter that indicates that
setValue should push to all widgets of the same "group", it opens a thread
that sets them all and leaves.
Signaling across threads can solve that easily :)
2010/1/22 Koen Deforche <[email protected]>
> Hey Omer,
>
> If you want to push data to other sessions, then you will need to
> enableUpdates() for these other session before hand, within the event
> loop of the corresponding session.
>
> >
> > This of course doesn't work.
> > Shouldn't it be pushing to all widgets automatically?
>
> How could it possibly know when to push changes ?
>
> > Also why in a signal there isn't a findSlot() and clearSlots() functions?
>
> Because you can achieve the same with a boost::connection object,
> returned from each connect() call.
>
> > 2010/1/21 omer katz <[email protected]>
> >>
> >> This now works for a single session but not for every session.
> >> What I want is that all sessions will update their ExampleWidget when
> one
> >> of them is updated.
> >>
> >> Are you aware that you guys are using boost.signal and not boost.signal2
> >> behind the hood?
> >> Is it possible that it will also cause problems?
> >> boost.signal isn't thread safe while boost.signal isn't.
>
> There is no benefit of thread-safety in using boost::signal versus
> boost signal2 for Wt: we are never not using signaling across threads,
> not even when you are in the scenario of the simplechat example or
> your scenario. Manipulating a single application is protected by a
> mutex (the Update lock).
>
> Regards,
> koen
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for
> Conference
> attendees to learn about information security's most important issues
> through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest