Boost logo

Boost Users :

Subject: [Boost-users] [Asio] Need help making a custom service
From: Kyle Edwards (kedwards_at_[hidden])
Date: 2015-03-09 13:49:44


Hello everyone,

First off, I would like to say that I have been using Boost for the past
few years, and have found it very useful. Thanks for all your hard work!

Second, I have a question about making a custom service. I would like to
make a service that triggers a callback when a GPIO pin changes state
and triggers an interrupt (I'm using a Raspberry Pi.) I have (or can
obtain) a file descriptor that can be poll()'d, select()'d, or epoll'd
and which omits high-priority events (POLLPRI, EPOLLPRI, etc.). This
entire use case is pretty Linux-specific, so it doesn't have to be very
portable. What I would like to be able to do is something like this:

// CODE STARTS HERE

#include <iostream>
#include <boost/asio.hpp>

class gpio_interrupt {
public:
  gpio_interrupt(boost::asio::io_service &io_service,
                 unsigned int number)
  {
    // Asio magic goes here
  }

  template <typename Callback>
  void async_wait(Callback c)
  {
    // Asio magic goes here
  }
};

static void my_callback(const boost::system::error_code &ec)
{
  if (ec)
    return;

  std::cout << "Pin changed state" << std::endl;
}

int main(int argc, char **argv)
{
  boost::asio::io_service io_service;
  gpio_interrupt interrupt(io_service, 21);
  interrupt.async_wait(my_callback);

  io_service.run();

  return 0;
}

// CODE ENDS HERE

I've looked a little bit at the Boost.Asio code (in particular the
socket code) to get an idea of how I would do this, but there are so
many different classes and inner classes that I'm not sure where to get
started. Can someone help me? Thanks in advance!

--

Kyle Edwards

Software Developer





20 Corporate Circle | Albany, NY 12203

office 888-4BULLEX | 518.689.2023 | fax 518.689.2034 | web:
www.bullex.com





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net