Hey Mike,
2010/7/29 Mike Teehan <[email protected]>:
> Hello Everyone,
>
> My application creates a global data model in main() and createApplication()
> passes a pointer to the model into each application. When a change is made to
> the model (properly mutex'd, of course), the changes immediately show in the
> instance that made them, but not any others. Other instances seem to have
> access to the updated model, but don't receive update notification. After
> referencing the simplechat example, I've tried getUpdateLock and
> triggerUpdate, but they don't seem to trigger the update in the other
> instances.
I think sharing a model between applications is a nice use-case, which
we have contemplated on supporting before, but is currently not
supported.
The part that is currently missing is proper (safe) signal
propagation: a view connects its methods to the model's signals, in
order to be notified of changes. When the signal is emitted, these
methods will be called. If the view belongs to another application,
this is not safe/correct since that other application's update-lock is
not taken first.
This could in principle be fixed though: in Signal::connect(), we know
that the current application instance is the View application. We
could keep track of that application together with the method, and
grab its update lock before emitting the method.
In fact, if we make the calls to the signal accessor methods of
WAbstractItemModel (such as changed()) virtual (and I cannot see any
argument against this!), then we could design a proxy model that does
something like this (and I know you love proxy models!):
with:
typedef std::map<WApplication *app, Signal<WModelIndex, WModelIndex>
> ChangedSignalsMap;
ChangedSignalsMap changedSignals_
we could reimplement changed():
Signal<WModelIndex, WModelIndex>& WCrossAppProxyModel::changed()
{
WApplication *app = WApplication::instance();
return changedSignals_[app];
}
and the method that propagates the change from the source model:
void WCrossAppProxyModel::sourceModelChanged(const WModelIndex& m1,
const WModelIndex& m2)
{
for (ChangedSignalsMap::const_iterator i = changedSignals_.begin();
i != changedSignals_.end(); ++i) {
WApplication::UpdateLock lock(i->first);
i->second.emit(m1, m2);
if (serverPush_)
i->first->triggerUpdate();
}
}
The only one more complication is to keep track of applications that
die, but there are solutions to that (such as explicit registrying, or
abusing a boost::connection's lifetime tracking to discover whether
the app still exists).
Regards,
koen
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest