[Fresco-devel] flyweighting the commands behind triggers
Nick Lewycky <[email protected]>
| Newsgroups | gmane.comp.video.fresco.devel |
|---|---|
| Message-ID | <[email protected]> |
Even though the Command->execute function takes a CORBA::Any, there's no way to pass data to it through a button you've just created. In order to facilitate flyweighting of CommandImpls, I'd like to add a "payload" attribute to the Trigger that changes what the ToolKit passes in when it calls execute. At the moment, it just passes in a useless blank. My attached patch implements such an attribute. I'd like review. Please answer the question, does it copy correctly and not leak memory? I have no idea myself. Otherwise, I'd like this to get checked in soon so I can show you all my Fresco Minesweeper game. :) (Think about it. All those buttons, all the same. What could be a better case for flyweighting?) Thanks, Nick Lewycky
command-flyweight.patch
(text/plain, 3.7 KB)
Index: Berlin/modules/Tools/Stepper.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/Stepper.cc,v
retrieving revision 1.7
diff -u -w -r1.7 Stepper.cc
--- Berlin/modules/Tools/Stepper.cc 29 May 2002 06:49:40 -0000 1.7
+++ Berlin/modules/Tools/Stepper.cc 22 Jul 2002 22:55:09 -0000
@@ -64,8 +64,7 @@
void Stepper::step()
{
Trace trace("Stepper::step");
- CORBA::Any any;
- execute(any);
+ execute();
}
void Stepper::start()
Index: Berlin/modules/Tools/TriggerImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/TriggerImpl.cc,v
retrieving revision 1.11
diff -u -w -r1.11 TriggerImpl.cc
--- Berlin/modules/Tools/TriggerImpl.cc 29 May 2002 06:49:40 -0000 1.11
+++ Berlin/modules/Tools/TriggerImpl.cc 22 Jul 2002 22:55:09 -0000
@@ -29,7 +29,7 @@
using namespace Prague;
using namespace Fresco;
-TriggerImpl::TriggerImpl() : ControllerImpl(false) {}
+TriggerImpl::TriggerImpl() : ControllerImpl(false), _data() {}
TriggerImpl::~TriggerImpl()
{
Trace trace("Trigger::~Trigger");
@@ -55,6 +55,17 @@
return Command::_duplicate(_command);
}
+void TriggerImpl::payload(const CORBA::Any &a)
+{
+ Trace trace("TriggerImpl::payload");
+ _data = new CORBA::Any(a);
+}
+
+CORBA::Any *TriggerImpl::payload()
+{
+ return _data;
+}
+
void TriggerImpl::release(PickTraversal_ptr traversal, const Input::Event &event)
{
/*
@@ -63,8 +74,7 @@
*/
if (inside(traversal) && test(Fresco::Controller::pressed))
{
- CORBA::Any dummy;
- try { execute(dummy);}
+ try { execute();}
catch (...) {}
}
ControllerImpl::release(traversal, event);
@@ -78,20 +88,19 @@
set(Fresco::Controller::pressed);
if (test(Fresco::Controller::pressed))
{
- CORBA::Any dummy;
- execute(dummy);
+ execute();
clear(Fresco::Controller::pressed);
}
}
else ControllerImpl::key_press(event);
}
-void TriggerImpl::execute(const CORBA::Any &any)
+void TriggerImpl::execute()
{
Trace trace("TriggerImpl::execute");
Prague::Guard<Mutex> guard(_mutex);
if (!CORBA::is_nil(_command))
- try { _command->execute(any);}
+ try { _command->execute(*_data);}
catch (const CORBA::OBJECT_NOT_EXIST &) { _command = Fresco::Command::_nil();}
catch (const CORBA::COMM_FAILURE &) { _command = Fresco::Command::_nil();}
}
Index: Berlin/modules/Tools/TriggerImpl.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/TriggerImpl.hh,v
retrieving revision 1.6
diff -u -w -r1.6 TriggerImpl.hh
--- Berlin/modules/Tools/TriggerImpl.hh 29 May 2002 06:49:40 -0000 1.6
+++ Berlin/modules/Tools/TriggerImpl.hh 22 Jul 2002 22:55:09 -0000
@@ -37,10 +37,13 @@
~TriggerImpl();
void action(Fresco::Command_ptr);
Fresco::Command_ptr action();
+ void payload(const CORBA::Any &);
+ CORBA::Any *payload();
virtual void release(Fresco::PickTraversal_ptr, const Fresco::Input::Event &);
virtual void key_press(const Fresco::Input::Event &);
- void execute(const CORBA::Any &);
+ void execute();
private:
+ CORBA::Any *_data;
Prague::Mutex _mutex;
Fresco::Command_var _command;
};
Index: Fresco/idl/Fresco/Trigger.idl
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco/idl/Fresco/Trigger.idl,v
retrieving revision 1.6
diff -u -w -r1.6 Trigger.idl
--- Fresco/idl/Fresco/Trigger.idl 29 May 2002 06:57:01 -0000 1.6
+++ Fresco/idl/Fresco/Trigger.idl 22 Jul 2002 22:55:10 -0000
@@ -40,6 +40,7 @@
//. The Trigger will execute this Command (if it is not nil) when
//. clicked.
attribute Command action;
+ attribute any payload;
};
};