1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/*
* This file is part of buteo-syncfw package
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef IPHEARTBEAT_H
#define IPHEARTBEAT_H
#include <QObject>
#include <QMap>
#include <QSocketNotifier>
extern "C" {
#include "iphbd/libiphb.h"
}
namespace Buteo {
/// \brief IPHeartBeat implementation.
///
/// This class manages heart beats for different profiles.
class IPHeartBeat : public QObject
{
Q_OBJECT
/// \brief Internal structure to hold profile-iphb stucture-notifier map
struct BeatStruct {
int sockfd;
QSocketNotifier *sockNotifier;
iphb_t iphbHandle;
};
public:
/*! \brief Constructor.
* \param aParent Parent object.
*/
IPHeartBeat(QObject *aParent);
/**
* \brief Destructor
*/
virtual ~IPHeartBeat();
/*! \brief Schedules a heartbeat for this profile between minWaitTime and maxWaitTime.
*
* The beat will be generated between minWaitTime and maxWaitTime seconds
* \param aProfName Name of the profile.
* \param aMinWaitTime Minimum wait time in seconds.
* \param aMaxWaitTime Minimum wait time in seconds.
* \return Success indicator.
*/
bool setHeartBeat(const QString &aProfName, ushort aMinWaitTime, ushort aMaxWaitTime);
/*! \brief Removes heart beat waiting for a profile.
*
* \param aProfName Name of the profile.
*/
void removeWait(const QString &aProfName);
/*! \brief Removes heart beat waiting for all profiles.
*/
void removeAllWaits();
signals:
/*! \brief This signal will be emitted when a heartbeat for particular profile is triggered.
*
* \param aProfName Name of the profile for which heart beat is triggered.
*/
void onHeartBeat(QString aProfName);
private slots:
/*! \brief This signal will be emitted when a socket descriptor gets an event notification.
*
* \param aSockFd Socket descriptor who got the event.
*/
void internalBeatTriggered(int aSockFd);
private:
/*! \brief Finds the name of the profile which uses particular file descriptor
*
* \param aSockFd Socket descriptor.
* \param aProfName name of the profile.
* \return true if profile name found, otherwise false
*/
bool getProfNameFromFd(int aSockFd, QString &aProfName);
private:
///Map of structures waiting for heart beat
QMap<QString, BeatStruct> iBeatsWaiting;
#ifdef SYNCFW_UNIT_TESTS
friend class IPHeartBeatTest;
#endif
};
}
#endif
|