xynopsis | 2 Feb 19:56 2006
Picon

[Wt-interest] New signal and slots implementation

Hi,

I'm now extending Wt 1.14 to make it work my custom
signal and slots implementation for a typesafe and
crash-free callback mechanism. I'll try to make the
transition as smooth as possible by re-using existing
classes as wrappers.
I have also revamped my signal and slots library with
a few small improvements that make it somewhat
slightly better, IMHO, to sigc and boost::signal/slots
:-). For example, slots can be overloaded without
using some sort of bind method. Ojects that emitted
the signal can also be also identified inside calling
slots without using a SignalMapper class making the
WSignalMapper uneccessary. This approach closely
follows Qt Signal and Slots without the burden of an
external meta-compiler. The compiler catches signal -
slots mismatches and displays errors without being too
verbose.
I hope to submit the code for your review as soon as I
finish the port.

Thanks for your information about the static slots. I
think I have grasped it quite a bit. Tracing those
undoTriggers and setStatic methods also helped a lot!
Right now, I'm re-building WSlotInstance based on my
Slot class.

Best regards,
Abdiel
(Continue reading)

xynopsis | 2 Feb 20:35 2006
Picon

Re: [Wt-interest] New signal and slots implementation

What to expect:
Signal - slots various styles in syntax

//Declaring signals:
class X 
{
public
...
void update();

Signal<int, const std::string&, const mytype&> sig
};

// A slot can be any ordinary member function
class Y
{
public
...
void function(int x, const std::string& s, const
mytype& t)
 {
  std::cout << x << s << t.toString() << std::endl;
 }
};

//Connecting signals to slots
X obj1;
Y obj2;
// boost/sigc-like syntax:
obj.sig.connect(SLOT(&obj, Y::function));
(Continue reading)

Tomas Lindquist Olsen | 3 Feb 01:51 2006
Picon

Re: [Wt-interest] non apache trouble.

Thanx for the pointers.
It has turned up a little overwhelming though, so for now I have installed apache so I can try it out.
When I feel more confident with witty, I'll go back and see if I can make any sense of it.

witty does seems excellent though. So far I like it alot, great work.
The only thing is really the whole signal/slot stuff. I would love to see a standard c++ implementation as suggested in another thread.

-Tomas

On 1/31/06, Koen Deforche <koen.deforche <at> gmail.com> wrote:
Hey Tomas,

sorry for the late reply, but I am on travel for the next month, and Wt is still
a hobby endeavour.

> I'm trying to get this to work with lighttpd, but I'm having some trouble.
> I start the application ( hello.fcg) before starting the server, binding it
> to port 1027 on ' 127.0.0.1'
>
> I then start the server, at go to the link, and something is happening, but
> I get an endless loop of new sessions.
> First time it redirects me to same place with a session id and js+ajax=yes
> but it then "immediately" redirects to a new page with a new session id.

This is the behaviour when the child (session-specific) process has died
for some reason and therefore a new session gets allocated. But you should
be able to see this in the log file.

> I can see these session in "/opt/wt/run" where I installed it.
> The fcgi process is running as a dedicated user "witty" with write access to
> only that location.

That should be fine.

> I hope you can provide some pointers to what I should be looking at /
> debugging.
> I don't have alot of experience in network programming, but I know C++ very
> well and can do some testing.
> but I would really like to see this in action without using apache.

What do you get in the 'error-log' file equivalent of apache in lightpd ?
I have no real idea why it goes wrong, but I am always curious at a bug fix :-)
The two .C files to watch are web/Server.C and web/WebSession.C

koen


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
witty-interest mailing list
witty-interest <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Koen Deforche | 3 Feb 10:32 2006
Picon

Re: [Wt-interest] New signal and slots implementation

Hey Abdiel,

> What to expect:
> Signal - slots various styles in syntax
>
> //Declaring signals:
> class X
> {
> public
> ...
> void update();
>
> Signal<int, const std::string&, const mytype&> sig
> };
>
> // A slot can be any ordinary member function
> class Y
> {
> public
> ...
> void function(int x, const std::string& s, const
> mytype& t)
>  {
>   std::cout << x << s << t.toString() << std::endl;
>  }
> };
>
> //Connecting signals to slots
> X obj1;
> Y obj2;
> // boost/sigc-like syntax:
> obj.sig.connect(SLOT(&obj, Y::function));
> // Qt-like syntax:
> Object::connect(SIGNAL(&obj1, sig), SLOT(&obj2,
> Y::function));

This looks nice.

It is still necessary for the objects to extend from a base class (Object ?)
in order to track their deletions, right ?

I think you can ignore the static slot stuff initially, just leave the 'undo'
functions there dangling. And then we can work out a syntax for them,
we can re-add something that fits better in the new signal/slot
implementation.

Exciting stuff !

Regards,
koen

xynopsis | 13 Feb 19:07 2006
Picon

Re: [Wt-interest] New signal and slots implementation

Koen,

After many sessions of late-night codings, I finally
succeeded, albeit, only slightly successful in
integrating the new template-based signal-slots
implementation. ;-)
I have replaced both the WSignalInstance and
WSLotInstance with the custom classes that does away
with moc. I'm excited that it compiled without hitches
after much tweaking! 
My problem now is that I can't seem to find a way to
prevent event signals from firing away every time
there is an event from the mouse/kb. Currently, Wt's
behaviour is starting to become as real-time as
Desktop toolkits. Now this is bad for web apps! I
noticed that Wt is now generating lots of signals (see
attached HTML source for Hello World).
Basically, what I did was derive from my Signal and
Slots classes and re-implemented the rest of the
methods in your WSignalInstance/WSLotInstance 

Perhaps, was it because the static slot functionality
was gone? What are your thoughts on these?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><html lang="en"
dir="ltr">
<head>
<meta http-equiv='Pragma' content='no-cache' />
<title></title>
<style type="text/css">
*.suggestion:hover { border: none;background-color:
yellow; }
*.tabbutton { cursor: pointer;border: medium outset
;background-color: yellow; }
*.tabbuttoncurrent { border: medium solid
olive;background-color: yellow; }
DIV, TD, IMG { margin: 0px; padding: 0px; }
TABLE { border-collapse: collapse; border: 0px }

</style>
<script language="JavaScript">
var formObjects = new Array();
var keepAliveTimer;function keepAlive() {
  update('none');
  keepAliveTimer = setTimeout('keepAlive()', 295000);
}
function doOnLoad() {
  update('load');
  keepAliveTimer = setTimeout('keepAlive()', 295000);
}
var url = '/hello?sessionid=UHEaYIRrfQrODzlk';
var appUrl = '/hello';
function getElement(id) {
  var el = document.getElementById(id);
  if (!el)
    for (var i = 0; i < window.frames.length; ++i) {
      el =
window.frames[i].document.getElementById(id);
      if (el)
        return el;
    }
  return el;
}
var message_tx_num = 0;
var message_rx_num = 0;
var messages = new Array();
var requests = new Array();
function callback() {
  var i;
  for (i = message_rx_num; i < requests.length; ++i) {
    if ((requests[i] != null)
        && (requests[i].readyState == 4)) {
      try {
        var msg =
requests[i].responseText.substring(5);
        var message_num =
parseInt(requests[i].responseText.substring(0, 5));
        requests[i] = null;
        if (message_rx_num != message_num) {
          if ((message_tx_num - message_rx_num) > 5)
            document.location.reload();
          messages[message_num] = msg;
        } else {
          eval(msg);
          message_rx_num++;
          while (typeof messages[message_rx_num] !=
'undefined') {
            eval(messages[message_rx_num]);
            messages[message_rx_num]=null;
            message_rx_num++;
          }
        }
      } catch (e) {
        alert(e.name + ': ' + e.message);
      }
    }
  }
}
function update(signalName) {
  var xmlHttpReq = false;
  if (window.XMLHttpRequest) {
    xmlHttpReq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    xmlHttpReq = new
ActiveXObject("Microsoft.XMLHTTP");
  }
  requests.push(xmlHttpReq);
  var query = '&signal=' 
     + signalName + '&msg=' + message_tx_num++ +
'&rand=' + Math.round(Math.random()*1000000);
  for (x in formObjects) {
    var el = getElement(formObjects[x]);
    if ((el.type != 'file') 
        && (((el.type != 'checkbox')&&(el.type !=
'radio')) || el.checked))
      query += '&' + formObjects[x] + '=' +
escape(el.value);
  }
  xmlHttpReq.open('GET', url + query, true);
  xmlHttpReq.onreadystatechange = callback;
  xmlHttpReq.send('');
}
function hide(o) { getElement(o).style.display =
'none'; }
function inline(o) { getElement(o).style.display =
'inline'; }
function block(o) { getElement(o).style.display =
'block'; }
</script>
</head>
<body onload="doOnLoad();">
<form method='post'
action='/hello?sessionid=UHEaYIRrfQrODzlk' id='form'
enctype='multipart/form-data'>
  <input name='signal' id='signal' type='hidden'
value='none'></input>
  <input name='request' id='request' type='hidden'
value='page'></input><div id='o1'
onclick='update("s04629018");'
ondblclick='update("s04629030");'
onmousedown='update("s04629048");'
onmousemove='update("s046290a8");'
onmouseout='update("s04629078");'
onmouseover='update("s04629090");'
onmouseup='update("s04629060");'
style='text-align:left;'><span id='o2'
onclick='update("s0462ab88");'
ondblclick='update("s0462aba0");'
onmousedown='update("s0462abb8");'
onmousemove='update("s0462ac18");'
onmouseout='update("s0462abe8");'
onmouseover='update("s0462ac00");'
onmouseup='update("s0462abd0");'><h1>Hello,
World!</h1></span><button id='o3' type='button'
onblur='update("s0462bd60");'
onchange='update("s0462bd30");'
onclick='update("s0462bc20");'
ondblclick='update("s0462bc38");'
onfocus='update("s0462bd78");'
onmousedown='update("s0462bc50");'
onmousemove='update("s0462bcb0");'
onmouseout='update("s0462bc80");'
onmouseover='update("s0462bc98");'
onmouseup='update("s0462bc68");'
onselect='update("s0462bd48");'>Quit</button></div>

</form>
<hr /><span style='font-size: smaller;'><a
href="http://witty.sourceforge.net/">Download source
here</a></span>
</body></html>

I also have some questions. (1)Does
WebSession::handleRequestData() read in/convert to
pointers all signals embedded in the HTML page or only
event signals (i.e, exposable set to true)? (2) What's
the purpose of the std::set exposedSignal on
WApplication other than determing if a signal
isExposedSignal()?
(3) What actually determines when a signal declared on
 C++ code gets to embed (as s0xdeadbeef HEX) in the
HTML page and fired by the user?

About that static slot thing, I'm thinking about
replacing the idea with dynamic caching of the
JavaScript code. This way, users would no longer have
to manually specify an 'undo' method evyerytime they
want a good-performing slot. 

I really would like to hear your insights on how the
internals of Wt works. I have traced your code but I
think it would still be best to here from you. I hope
to release code as soon as the kinks get ironed out!

Cheers,
Abdiel

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Koen Deforche | 13 Feb 19:25 2006
Picon

Re: [Wt-interest] New signal and slots implementation

Abdiel,

This looks really good !

> My problem now is that I can't seem to find a way to
> prevent event signals from firing away every time
> there is an event from the mouse/kb. Currently, Wt's
> behaviour is starting to become as real-time as
> Desktop toolkits. Now this is bad for web apps! I
> noticed that Wt is now generating lots of signals (see
> attached HTML source for Hello World).
> Basically, what I did was derive from my Signal and
> Slots classes and re-implemented the rest of the
> methods in your WSignalInstance/WSLotInstance
>
> Perhaps, was it because the static slot functionality
> was gone? What are your thoughts on these?

No, what basically went wrong is that the code that
protects the signal from being 'implemented' as an event
handler is apparently broken. For example,
see WWebWidget.C : updateSignalConnection(...):

    if (isConnected(s))
      element.setEventSignal(eventName, *s, argName, condition);
    else
      element.removeEventSignal(eventName);

where isConnected(s) is implemented as s->isConnected();

Have you implemented this method ? It should keep track of the
fact that at least one slot has been connected to the signal.

> I also have some questions. (1)Does
> WebSession::handleRequestData() read in/convert to
> pointers all signals embedded in the HTML page or only
> event signals (i.e, exposable set to true)? (2) What's
> the purpose of the std::set exposedSignal on
> WApplication other than determing if a signal
> isExposedSignal()?

The idea of isExposedSignal() is a basic security check: it
is to filter invalid from valid signals, to make sure a hacker cannot
just execute arbitrary slots which are internal to your application.
Other than that, it does not add any functionality. You should expect
that signals that are exposed get really exposed. This code is
irrelevant except in the light of security.

> (3) What actually determines when a signal declared on
>  C++ code gets to embed (as s0xdeadbeef HEX) in the
> HTML page and fired by the user?

The signal->isConnected().

> About that static slot thing, I'm thinking about
> replacing the idea with dynamic caching of the
> JavaScript code. This way, users would no longer have
> to manually specify an 'undo' method evyerytime they
> want a good-performing slot.

That is true. Still, the first call will still be slow. I am not sure
how good I can judge whether this would feel 'bad' or 'good',
unless we try the implementation. I thought of going for three
options:

1) dynamic slot, default
2) static slot, auto-learn
3) static slot, pre-learn, with undoMethod() provided.

> I really would like to hear your insights on how the
> internals of Wt works. I have traced your code but I
> think it would still be best to here from you. I hope
> to release code as soon as the kinks get ironed out!

In fact, if you feel that way, I am happy to finish the code
where it delves more into Wt internals...

Great work, I must say. I am sure it was harder than expected
since Wt was a bit too much interwoven with the
current signal/slot implementation !

Regards,
koen

xynopsis | 21 Feb 11:33 2006
Picon

[Wt-interest] New signal and slots RELEASE

Hello developers!

I am pleased to announce that I have successfuly
integrated "XLObject" to Witty.

http://openkiosk.sourceforge.net/wt/wt-1.0.14-xlobject.tar.gz

I have used my own project webspace since I don't own
a server on the web. :(

I have modified the Witty homepage, helloworld, and
Hangman by Will webapps to reflect the new signal -
slots implementation that throws away:
(1) tediously writing // MOC ... comments above signal
and slots or Object declarations
(2) tediously writing public slots: public signals: or
W_OBJECT macros in class definitions.
(2) The moc meta-compiler!
(3) WSignalMapper

Wt projects are now standard C++ code that can be
compiled directly by any recent C++ compiler.

Please read
http://openkiosk.sourceforge.net/wt/README.txt for
more information about the signal-slots implementation
used.

Developers, Please download and test! I would happily
welcome your feedback.
The project is extensively valgrinded and I have also
fixed some minor memory leak errors in
WebSession::generateResponse()

Cheers!
abj

(i'm going to sleep now!)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

xynopsis | 21 Feb 12:08 2006
Picon

Re: [Wt-interest] New signal and slots RELEASE

The signal and slots library included with Wt was a
revamped XLObject that was stripped of unecessary
features. This is now the final syntax when connecting
objects.

Wt new signal - slots. Final syntax:

//Declaring signals:
class X: public WObject
{
public
...
void update();

Signal<int, const std::string&, const mytype&> sig
Signal<int, const std::string&, const mytype&> sig2
};

// A slot can be any ordinary member function on
// a class derived from WObject or XL::Object
class Y: public WObject
{
public
...
void function(int x, const std::string& s, const
mytype& t)
 {
  std::cout << x << s << t.toString() << std::endl;
 }
void fnless(int x, const std::string& s)
 {
  std::cout << x << s << std::endl;
 }
void noarg() { std::cout << "noarg" << std::endl; }
};

//Connecting signals to slots
X obj1;
Y obj2;
// shortcut connection syntax 
obj.sig.connect(SLOT(&obj2, Y::function));
// or 
obj.sig.connect(&obj2, &Y::fnless);
// connect to slot with lesser signature
obj.sig.connect(&obj2, &Y::noarg);

// emitting signals
void X::update()
{
  mytype m;

  // emit signal directly without including sender
info
  sig.emit(100, "hello world", m);

  // Proper way to emit signal and enable sender info
  emit(sig(100, "hello world", m));
}

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Koen Deforche | 21 Feb 12:14 2006
Picon

[Wt-interest] Re: New signal and slots RELEASE

Abdiel,

this looks fantastic. I have no time to go through t it now in detail, but will
as soon as possible ! Nice job !

I did notice that you still left the //MOC kludge comments in the files ?

Regards,
koen

On 2/21/06, xynopsis <xynopsis@...> wrote:
> Hello developers!
>
> I am pleased to announce that I have successfuly
> integrated "XLObject" to Witty.
>
> http://openkiosk.sourceforge.net/wt/wt-1.0.14-xlobject.tar.gz
>
> I have used my own project webspace since I don't own
> a server on the web. :(
>
> I have modified the Witty homepage, helloworld, and
> Hangman by Will webapps to reflect the new signal -
> slots implementation that throws away:
> (1) tediously writing // MOC ... comments above signal
> and slots or Object declarations
> (2) tediously writing public slots: public signals: or
> W_OBJECT macros in class definitions.
> (2) The moc meta-compiler!
> (3) WSignalMapper
>
> Wt projects are now standard C++ code that can be
> compiled directly by any recent C++ compiler.
>
> Please read
> http://openkiosk.sourceforge.net/wt/README.txt for
> more information about the signal-slots implementation
> used.
>
> Developers, Please download and test! I would happily
> welcome your feedback.
> The project is extensively valgrinded and I have also
> fixed some minor memory leak errors in
> WebSession::generateResponse()
>
> Cheers!
> abj
>
> (i'm going to sleep now!)
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>

Tomas Lindquist Olsen | 21 Feb 12:24 2006
Picon

Re: [Wt-interest] Re: New signal and slots RELEASE

looks awesome. time to try this baby out again :D

-Tomas

On 2/21/06, Koen Deforche <koen.deforche <at> gmail.com > wrote:
Abdiel,

this looks fantastic. I have no time to go through t it now in detail, but will
as soon as possible ! Nice job !

I did notice that you still left the //MOC kludge comments in the files ?

Regards,
koen

On 2/21/06, xynopsis <xynopsis <at> yahoo.com > wrote:
> Hello developers!
>
> I am pleased to announce that I have successfuly
> integrated "XLObject" to Witty.
>
> http://openkiosk.sourceforge.net/wt/wt-1.0.14-xlobject.tar.gz
>
> I have used my own project webspace since I don't own
> a server on the web. :(
>
> I have modified the Witty homepage, helloworld, and
> Hangman by Will webapps to reflect the new signal -
> slots implementation that throws away:
> (1) tediously writing // MOC ... comments above signal
> and slots or Object declarations
> (2) tediously writing public slots: public signals: or
> W_OBJECT macros in class definitions.
> (2) The moc meta-compiler!
> (3) WSignalMapper
>
> Wt projects are now standard C++ code that can be
> compiled directly by any recent C++ compiler.
>
> Please read
> http://openkiosk.sourceforge.net/wt/README.txt for
> more information about the signal-slots implementation
> used.
>
> Developers, Please download and test! I would happily
> welcome your feedback.
> The project is extensively valgrinded and I have also
> fixed some minor memory leak errors in
> WebSession::generateResponse()
>
> Cheers!
> abj
>
> (i'm going to sleep now!)
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
witty-interest mailing list
witty-interest <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest


Gmane