libhal C++ wrapper

Milosz Derezynski internalerror at gmail.com
Sat Nov 18 20:52:55 PST 2006


Hi Everyone

I'd like to announce that i've begun work on a libhal C++ wrapper, first
starting with the core libhal, and next will be libhal-storage. The API is
very similar to e.g. cairomm or glibmm, using RefPtrs, etc.

So far we have 2 basic first-class objects, HAL::Context and HAL::Device,
HAL::Device being a "virtual" class in the sense that it has no direct
representation in the C API (rather the context can be used to acquire
information about devices); HAL::Device is basically just a convenience
class to bundle methods and manage state related to a device.

(I'd also like to put attention onto the fact that the API is mostly/solely
geared towards applications, and hence does not implement, for now at least,
things that e.g. hald-addon daemons would use, since these are likely to be
just written in C anyway).

The PS/PSI system is also wrapped in an STL like fashion and can be quite
well integrated with standard C++ code.


Here's an usage example, it is included in the halcc-0.1.tar.gz tarball:


#include <iostream>
#include <dbus/dbus.h>
#include <hal++/hal++-types.hh>
#include <hal++/hal++-context.hh>
#include <hal++/hal++-device.hh>

int main (int argc, char** argv)
{
  DBusError error;
  dbus_error_init (&error);
  DBusConnection * c = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
  HAL::RefPtr<HAL::Context> context =  HAL::Context::create (c);

  HAL::StrV list (context->find_device_by_capability ("volume"));
  for (HAL::StrV::const_iterator i = list.begin (); i != list.end (); ++i)
  {
    HAL::RefPtr<HAL::Device> device = HAL::Device::create (context, *i);
    if (device->get_property <bool> ("volume.is_mounted"))
    {
      std::cerr << "Volume with UDI '"
                << *i << "' is mounted on '"
                << device->get_property <std::string> ("volume.mount_point")
                << "'" << std::endl;
    }
  }
}


I've set up a small website on our project wiki here:
http://projects.beep-media-player.org/index.php/Main/HAL

Regards,
Milosz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/hal/attachments/20061119/fbedb808/attachment.html


More information about the hal mailing list