qavahiservicepublisher.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2011 Girish Ramakrishnan (girish@forwardbias.in)
  4. **
  5. ** Use, modification and distribution is allowed without limitation,
  6. ** warranty, liability or support of any kind.
  7. **
  8. ****************************************************************************/
  9. #ifndef QAVAHISERVICEPUBLISHER_H
  10. #define QAVAHISERVICEPUBLISHER_H
  11. #include <avahi-common/error.h>
  12. #include <avahi-common/malloc.h>
  13. #include <avahi-common/alternative.h>
  14. #include <avahi-client/client.h>
  15. #include <avahi-client/publish.h>
  16. #include <avahi-qt4/qt-watch.h>
  17. #include <QObject>
  18. class QAvahiServicePublisher : public QObject
  19. {
  20. Q_OBJECT
  21. public:
  22. QAvahiServicePublisher(QObject *parent = 0);
  23. ~QAvahiServicePublisher();
  24. struct Service {
  25. QString name;
  26. QString type;
  27. qint32 port;
  28. QString txtRecord;
  29. };
  30. void publish(const Service &service);
  31. void publish(const QString &serviceName, const QString &serviceType, qint32 port, const QString &txtRecord);
  32. int error() const { return m_error; }
  33. QString errorString() const { return m_errorString; }
  34. enum Notification {
  35. Error,
  36. ServicesRegistering,
  37. ServicesRegistered,
  38. ServiceNameCollision,
  39. ServicesUncommited,
  40. ServicesCommited,
  41. ClientConnecting,
  42. ServerRunning,
  43. ServerRegistering,
  44. ServerNameCollision
  45. };
  46. signals:
  47. void changeNotification(Notification notification);
  48. private:
  49. static void client_callback(AvahiClient *client, AvahiClientState state, void *userdata);
  50. void clientCallback(AvahiClient *client, AvahiClientState state);
  51. static void entry_group_callback(AvahiEntryGroup *group, AvahiEntryGroupState state, void *userdata);
  52. void entryGroupCallback(AvahiEntryGroup *group, AvahiEntryGroupState state);
  53. void initialize();
  54. void uninitialize();
  55. void doPublish(AvahiClient *client);
  56. void commit();
  57. QString m_serviceName;
  58. AvahiClient *m_client;
  59. AvahiEntryGroup *m_group;
  60. QList<Service> m_services;
  61. int m_error;
  62. QString m_errorString;
  63. };
  64. #endif // QAVAHISERVICEPUBLISHER_H