I've been experimenting with how we could handle locking/unlocking of
resources in Licq 2. I've uploaded the files to
http://ejohansson.se/files/licq/resources/ for you all to take a look
at. It's not complete in any way, but it compiles (for me at least).

An example may help to make it easier to understand. Take the current
class ICQUser. In this scheme it would implement ReadableResource and
WriteableResource (probably just by inheriting from some other class
that implements the two interfaces). The daemon would have a number of
ICQUser instances, all kept as boost::shared_ptr<ICQUser>.

When a plugin would like to read/write some info about a user it calls
daemon->getUser(...) which returns a ResourceHandle<ICQUser>. Then,
when the plugin is ready to read it does:
{
  ReadLocker<ICQUser> user(theHandle);
  user->getSomeData();
}

and to write it would do:
{
  WriteLocker<ICQUser> user(theHandle);
  user->setSomeData();
}

The locker classes ensures that the resource is properly locked and unlocked.

Comments?

// Erik

-- 
Erik Johansson
http://ejohansson.se/

Reply via email to