diff --git a/src/blackcore/voiceclient.h b/src/blackcore/voiceclient.h index 350a7a2f1..1308efa96 100644 --- a/src/blackcore/voiceclient.h +++ b/src/blackcore/voiceclient.h @@ -12,6 +12,7 @@ #include "../blackmisc/context.h" #include "../blackmisc/avcallsign.h" +#include "../blackmisc/vvoiceroom.h" #include @@ -45,8 +46,8 @@ namespace BlackCore virtual ~IVoiceClient() {} virtual void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) = 0; - virtual void joinVoiceServer(const uint32_t comUnit, const QString &serverSpec) = 0; - virtual void leaveVoiceServer(const uint32_t comUnit) = 0; + virtual void joinVoiceRoom(const uint32_t comUnit, const BlackMisc::Voice::CVoiceRoom &voiceRoom) = 0; + virtual void leaveVoiceRoom(const uint32_t comUnit) = 0; virtual void setVolume(const uint32_t comUnit, const uint32_t volumne) = 0; virtual void startTransmitting(const uint32_t comUnit) = 0; virtual void stopTransmitting(const uint32_t comUnit) = 0; @@ -57,6 +58,8 @@ namespace BlackCore virtual void getInputDevices(const uint32_t comUnit) = 0; virtual void getOutputDevices(const uint32_t comUnit) = 0; + virtual const BlackMisc::Voice::CVoiceRoom &voiceRoom (const uint32_t comUnit) = 0; + signals: void notConnected(const uint32_t comUnit); void connecting(const uint32_t comUnit); diff --git a/src/blackcore/voiceclient_vatlib.cpp b/src/blackcore/voiceclient_vatlib.cpp index ff69a056b..c014266a5 100644 --- a/src/blackcore/voiceclient_vatlib.cpp +++ b/src/blackcore/voiceclient_vatlib.cpp @@ -69,12 +69,12 @@ namespace BlackCore } - void CVoiceClientVatlib::onRoomStatusUpdate(Cvatlib_Voice_Simple *obj, roomStatusUpdate upd, int32_t roomIndex, void *cbVar) + void CVoiceClientVatlib::onRoomStatusUpdate(Cvatlib_Voice_Simple *obj, Cvatlib_Voice_Simple::roomStatusUpdate upd, int32_t roomIndex, void *cbVar) { } - void CVoiceClientVatlib::onRoomUserReceived(vatlib_Voice_Simple *obj, const char *name, void *cbVar) + void CVoiceClientVatlib::onRoomUserReceived(Cvatlib_Voice_Simple *obj, const char *name, void *cbVar) { } diff --git a/src/blackcore/voiceclient_vatlib.h b/src/blackcore/voiceclient_vatlib.h index b0b548cd5..f10a917a8 100644 --- a/src/blackcore/voiceclient_vatlib.h +++ b/src/blackcore/voiceclient_vatlib.h @@ -9,6 +9,7 @@ #include "voiceclient.h" #include +#include namespace BlackCore { @@ -41,12 +42,13 @@ namespace BlackCore private: // shimlib callbacks - void onRoomStatusUpdate(Cvatlib_Voice_Simple* obj, roomStatusUpdate upd, INT roomIndex, void* cbVar); - void onRoomUserReceived(vatlib_Voice_Simple* obj, const char* name, void* cbVar); + void onRoomStatusUpdate(Cvatlib_Voice_Simple* obj, Cvatlib_Voice_Simple::roomStatusUpdate upd, INT roomIndex, void* cbVar); + void onRoomUserReceived(Cvatlib_Voice_Simple* obj, const char* name, void* cbVar); void onHardwareDeviceReceived(Cvatlib_Voice_Simple* obj, const char* name, void* cbVar); QScopedPointer m_voice; BlackMisc::Aviation::CCallsign m_callsign; + QMap m_voiceRoomMap; }; diff --git a/src/blackmisc/vvoiceroom.cpp b/src/blackmisc/vvoiceroom.cpp new file mode 100644 index 000000000..fe9b23a56 --- /dev/null +++ b/src/blackmisc/vvoiceroom.cpp @@ -0,0 +1,90 @@ +#include "vvoiceroom.h" +#include "blackmisc/blackmiscfreefunctions.h" + +#include +#include + +namespace BlackMisc +{ + namespace Voice + { + CVoiceRoom::CVoiceRoom(const QString &serverSpec) : m_hostname(""), m_channel("") + { + if (serverSpec.contains("/")) + { + QStringList splittedSpec = serverSpec.split("/"); + m_hostname = splittedSpec.at(0); + m_channel = splittedSpec.at(1); + } + } + + /* + * Equal? + */ + bool CVoiceRoom::operator ==(const CVoiceRoom &other) const + { + if (&other == this) + { + return true; + } + + if (m_hostname == other.m_hostname && m_channel == other.m_channel) + { + return true; + } + + // otherwise + return false; + } + + /* + * Unequal? + */ + bool CVoiceRoom::operator !=(const CVoiceRoom &other) const + { + return !((*this) == other); + } + + uint CVoiceRoom::getValueHash() const + { + QList hashs; + hashs << qHash(m_hostname); + hashs << qHash(m_channel); + return BlackMisc::calculateHash(hashs, "CVoiceRoom"); + } + + void CVoiceRoom::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + QString CVoiceRoom::convertToQString(bool i18n) const + { + if (m_hostname.isEmpty() || m_channel.isEmpty()) return "Unknown"; + QString s = m_hostname; + s.append("/").append(m_channel); + return s; + } + + /* + * Marshall to DBus + */ + void CVoiceRoom::marshallToDbus(QDBusArgument &argument) const + { + argument << m_hostname; + argument << m_channel; + } + + /* + * Unmarshall from DBus + */ + void CVoiceRoom::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> m_hostname; + argument >> m_channel; + } + + + } // Voice +} // BlackMisc diff --git a/src/blackmisc/vvoiceroom.h b/src/blackmisc/vvoiceroom.h new file mode 100644 index 000000000..436ff1c1b --- /dev/null +++ b/src/blackmisc/vvoiceroom.h @@ -0,0 +1,139 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/*! + \file +*/ + +#include "valueobject.h" + +#include + + +#ifndef BLACKMISC_VOICEROOM_H +#define BLACKMISC_VOICEROOM_H + +namespace BlackMisc +{ + namespace Voice + { + /*! + * Value object encapsulating information of a voice room + */ + class CVoiceRoom : public BlackMisc::CValueObject + { + public: + + /*! + * Default constructor. + */ + CVoiceRoom() : m_hostname(""), m_channel("") {} + + /*! + * Constructor. + */ + CVoiceRoom(const QString &hostname, const QString &channel) : m_hostname(hostname), m_channel(channel) {} + + /*! + * Constructor. + */ + CVoiceRoom(const QString &serverSpec); + + /*! + * \brief QVariant, required for DBus QVariant lists + * \return + */ + virtual QVariant toQVariant() const + { + return QVariant::fromValue(*this); + } + + /*! + * Get the host name + * \return + */ + const QString &hostName() const { return m_hostname; } + + /*! + * Get the voice room + * \return + */ + const QString &channel() const { return m_channel; } + + /*! + * Set the host name + * \param + */ + void setHostName(const QString &hostName) { m_hostname = hostName; } + + /*! + * Set the voice channel + * \param + */ + void setChannel(const QString &channel) { m_channel = channel; } + + /*! + * \brief Valid voice room object? + * \return + */ + bool isValid() const { return !this->m_hostname.isEmpty() && !this->m_channel.isEmpty(); } + + /*! + * \brief Equal operator == + * \param other + * @return + */ + bool operator ==(const CVoiceRoom &other) const; + + /*! + * \brief Unequal operator == + * \param other + * @return + */ + bool operator !=(const CVoiceRoom &other) const; + + /*! + * \brief Value hash + */ + virtual uint getValueHash() const; + + /*! + * \brief Register metadata + */ + static void registerMetadata(); + + protected: + + /*! + * \brief Rounded value as string + * \param i18n + * \return + */ + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); + + + private: + QString m_hostname; + QString m_channel; + + }; + } // Voice +} // BlackMisc + +Q_DECLARE_METATYPE(BlackMisc::Voice::CVoiceRoom) + +#endif // BLACKMISC_VOICEROOM_H