// $Id: ReventLoop.hpp 513 2013-05-01 14:02:06Z mueller $
|
// $Id: ReventLoop.hpp 513 2013-05-01 14:02:06Z mueller $
|
//
|
//
|
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but
|
// This program is distributed in the hope that it will be useful, but
|
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
// 2013-05-01 513 1.1.1 fTraceLevel now uint32_t
|
// 2013-05-01 513 1.1.1 fTraceLevel now uint32_t
|
// 2013-02-22 491 1.1 use new RlogFile/RlogMsg interfaces
|
// 2013-02-22 491 1.1 use new RlogFile/RlogMsg interfaces
|
// 2013-01-11 473 1.0 Initial version
|
// 2013-01-11 473 1.0 Initial version
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: ReventLoop.hpp 513 2013-05-01 14:02:06Z mueller $
|
\version $Id: ReventLoop.hpp 513 2013-05-01 14:02:06Z mueller $
|
\brief Declaration of class \c ReventLoop.
|
\brief Declaration of class \c ReventLoop.
|
*/
|
*/
|
|
|
#ifndef included_Retro_ReventLoop
|
#ifndef included_Retro_ReventLoop
|
#define included_Retro_ReventLoop 1
|
#define included_Retro_ReventLoop 1
|
|
|
#include <poll.h>
|
#include <poll.h>
|
|
|
#include <cstdint>
|
#include <cstdint>
|
#include <vector>
|
#include <vector>
|
|
|
#include "boost/utility.hpp"
|
#include "boost/utility.hpp"
|
#include "boost/function.hpp"
|
#include "boost/function.hpp"
|
#include "boost/thread/mutex.hpp"
|
#include "boost/thread/mutex.hpp"
|
#include "boost/shared_ptr.hpp"
|
#include "boost/shared_ptr.hpp"
|
|
|
#include "librtools/RlogFile.hpp"
|
#include "librtools/RlogFile.hpp"
|
|
|
namespace Retro {
|
namespace Retro {
|
|
|
class ReventLoop : private boost::noncopyable {
|
class ReventLoop : private boost::noncopyable {
|
public:
|
public:
|
typedef boost::function<int(const pollfd&)> pollhdl_t;
|
typedef boost::function<int(const pollfd&)> pollhdl_t;
|
|
|
ReventLoop();
|
ReventLoop();
|
virtual ~ReventLoop();
|
virtual ~ReventLoop();
|
|
|
void AddPollHandler(const pollhdl_t& pollhdl,
|
void AddPollHandler(const pollhdl_t& pollhdl,
|
int fd, short events=POLLIN);
|
int fd, short events=POLLIN);
|
bool TestPollHandler(int fd, short events=POLLIN);
|
bool TestPollHandler(int fd, short events=POLLIN);
|
void RemovePollHandler(int fd, short events, bool nothrow=false);
|
void RemovePollHandler(int fd, short events, bool nothrow=false);
|
void RemovePollHandler(int fd);
|
void RemovePollHandler(int fd);
|
|
|
void SetLogFile(const boost::shared_ptr<RlogFile>& splog);
|
void SetLogFile(const boost::shared_ptr<RlogFile>& splog);
|
void SetTraceLevel(uint32_t level);
|
void SetTraceLevel(uint32_t level);
|
uint32_t TraceLevel() const;
|
uint32_t TraceLevel() const;
|
|
|
void Stop();
|
void Stop();
|
virtual void EventLoop();
|
virtual void EventLoop();
|
|
|
virtual void Dump(std::ostream& os, int ind=0, const char* text=0) const;
|
virtual void Dump(std::ostream& os, int ind=0, const char* text=0) const;
|
|
|
protected:
|
protected:
|
|
|
int DoPoll(int timeout=-1);
|
int DoPoll(int timeout=-1);
|
void DoCall(void);
|
void DoCall(void);
|
|
|
protected:
|
protected:
|
|
|
struct PollDsc {
|
struct PollDsc {
|
pollhdl_t fHandler;
|
pollhdl_t fHandler;
|
int fFd;
|
int fFd;
|
short fEvents;
|
short fEvents;
|
PollDsc(pollhdl_t hdl,int fd,short evts) :
|
PollDsc(pollhdl_t hdl,int fd,short evts) :
|
fHandler(hdl),fFd(fd),fEvents(evts) {}
|
fHandler(hdl),fFd(fd),fEvents(evts) {}
|
};
|
};
|
|
|
bool fLoopActive;
|
bool fLoopActive;
|
bool fUpdatePoll;
|
bool fUpdatePoll;
|
boost::mutex fPollDscMutex;
|
boost::mutex fPollDscMutex;
|
std::vector<PollDsc> fPollDsc;
|
std::vector<PollDsc> fPollDsc;
|
std::vector<pollfd> fPollFd;
|
std::vector<pollfd> fPollFd;
|
std::vector<pollhdl_t> fPollHdl;
|
std::vector<pollhdl_t> fPollHdl;
|
uint32_t fTraceLevel; //!< trace level
|
uint32_t fTraceLevel; //!< trace level
|
boost::shared_ptr<RlogFile> fspLog; //!< log file ptr
|
boost::shared_ptr<RlogFile> fspLog; //!< log file ptr
|
};
|
};
|
|
|
} // end namespace Retro
|
} // end namespace Retro
|
|
|
#include "ReventLoop.ipp"
|
#include "ReventLoop.ipp"
|
|
|
#endif
|
#endif
|
|
|