⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Wt
All Projects
Wt
Overview
Activity
Roadmap
Issues
Wiki
Forums
Download (1.49 KB)
Feature #285
» serverpush.cc
Koen Deforche
, 02/26/2010 03:02 PM
#include
<Wt/WApplication>
#include
<Wt/WContainerWidget>
#include
<Wt/WPushButton>
#include
<Wt/WLineEdit>
#include
<iostream>
#include
<boost/thread.hpp>
using
namespace
Wt
;
using
namespace
boost
;
using
namespace
std
;
class
ExampleWidget
;
class
CometTestApplication
:
public
WApplication
{
public:
CometTestApplication
(
const
WEnvironment
&
env
);
ExampleWidget
*
t
;
};
class
ExampleWidget
:
public
WLineEdit
{
boost
::
thread
updater
;
public:
void
startBigWork
()
{
wApp
->
enableUpdates
(
true
);
// enable server-push temporarily
updater
=
boost
::
thread
(
boost
::
bind
(
&
ExampleWidget
::
doWork
,
this
,
WApplication
::
instance
(),
text
()));
}
ExampleWidget
()
{
keyWentUp
().
connect
(
SLOT
(
this
,
ExampleWidget
::
startBigWork
));
}
void
doWork
(
WApplication
*
app
,
const
WString
s
)
{
WApplication
::
UpdateLock
uiLock
=
app
->
getUpdateLock
();
// RAII lock
cout
<<
endl
<<
s
<<
endl
;
setText
(
s
+
" "
+
s
);
cout
<<
endl
<<
text
()
<<
endl
;
// if using server push, push now the changes to the client
app
->
triggerUpdate
();
app
->
enableUpdates
(
false
);
// disable server-push again
}
};
CometTestApplication
::
CometTestApplication
(
const
WEnvironment
&
env
)
:
WApplication
(
env
)
{
t
=
new
ExampleWidget
();
root
()
->
addWidget
(
t
);
}
WApplication
*
createApplication
(
const
WEnvironment
&
env
)
{
return
new
CometTestApplication
(
env
);
}
int
main
(
int
argc
,
char
**
argv
)
{
return
WRun
(
argc
,
argv
,
&
createApplication
);
}
« Previous
1
2
Next »
(1-1/2)
Loading...