qcp/libqcp/qcp.h

106 lines
2.1 KiB
C
Raw Normal View History

2010-07-24 16:16:44 +00:00
#ifndef QCP_H
#define QCP_H
#include "libqcp_global.h"
#include <QObject>
#include <QLinkedList>
#include "../libqtavahi/qtavahi.h"
namespace QCP {
class LIBQCPSHARED_EXPORT Share;
class LIBQCPSHARED_EXPORT ShareDetails;
2010-07-24 16:16:44 +00:00
class LIBQCPSHARED_EXPORT Browse;
}
namespace QCP {
/* The private data of the Avahi::Service instances belongs to QCP ! :) */
class LIBQCPSHARED_EXPORT Browse : public QObject {
Q_OBJECT
private:
friend class QCP::Share;
struct ShareData {
QCP::ShareDetails *details;
2010-07-24 16:16:44 +00:00
void *data;
};
public:
Browse(QObject *parent = 0);
Avahi::Browse* avahiBrowse() { return m_av_browse; }
inline bool start() { return m_av_browse->start(); }
inline void stop() { m_av_browse->stop(); }
signals:
void found(QCP::Share s);
void lost(QCP::Share s);
void started();
void stopped();
private slots:
void foundService(Avahi::Service s);
void lostService(Avahi::Service s);
private:
static inline ShareData* shareData(const Avahi::Service &service) {
return static_cast<ShareData*>(service.data());
}
Avahi::Browse *m_av_browse;
};
class LIBQCPSHARED_EXPORT ShareDetails {
protected:
ShareDetails(const Avahi::Service &service) : m_service(service) { }
public:
virtual ~ShareDetails() { }
virtual QString methodName() = 0;
Avahi::Service service() const { return m_service; }
protected:
Avahi::Service m_service;
};
2010-07-24 16:16:44 +00:00
class LIBQCPSHARED_EXPORT Share {
private:
friend class QCP::Browse;
public:
inline Share(Avahi::Service service) : m_service(service) { }
inline Share() { }
2010-07-24 16:16:44 +00:00
public:
Avahi::Service avahiService() const { return m_service; }
inline void* data() const {
Browse::ShareData *sd = Browse::shareData(m_service);
return sd ? sd->data : 0;
}
inline void setData(void *data) const {
Browse::ShareData *sd = Browse::shareData(m_service);
if (sd) sd->data = data;
}
inline QCP::ShareDetails* details() const {
Browse::ShareData *sd = Browse::shareData(m_service);
return sd ? sd->details : 0;
}
2010-07-24 16:16:44 +00:00
private:
Avahi::Service m_service;
};
}
Q_DECLARE_METATYPE(QCP::Share);
Q_DECLARE_METATYPE(QList<QCP::Share>);
2010-07-24 16:16:44 +00:00
#endif // QCP_H