diff --git a/engine/Channel.cpp b/engine/Channel.cpp index 57c7ae61..ad69476d 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -67,6 +67,7 @@ static Mutex s_callidMutex(false,"CallID"); // this is to protect against two threads trying to (dis)connect a pair // of call endpoints at the same time static Mutex s_mutex(true,"CallEndpoint"); +static const String s_audioType = "audio"; CallEndpoint::CallEndpoint(const char* id) : m_peer(0), m_id(id), m_mutex(0) @@ -223,17 +224,17 @@ String CallEndpoint::getPeerId() const return id; } -DataEndpoint* CallEndpoint::getEndpoint(const char* type) const +DataEndpoint* CallEndpoint::getEndpoint(const String& type) const { - if (null(type)) + if (type.null()) return 0; const ObjList* pos = m_data.find(type); return pos ? static_cast(pos->get()) : 0; } -DataEndpoint* CallEndpoint::setEndpoint(const char* type) +DataEndpoint* CallEndpoint::setEndpoint(const String& type) { - if (null(type)) + if (type.null()) return 0; DataEndpoint* dat = getEndpoint(type); if (!dat) { @@ -259,9 +260,9 @@ void CallEndpoint::setEndpoint(DataEndpoint* endPoint) endPoint->connect(m_peer->getEndpoint(endPoint->toString())); } -void CallEndpoint::clearEndpoint(const char* type) +void CallEndpoint::clearEndpoint(const String& type) { - if (null(type)) { + if (type.null()) { ObjList* l = m_data.skipNull(); for (; l; l=l->skipNext()) { DataEndpoint* e = static_cast(l->get()); @@ -282,41 +283,46 @@ void CallEndpoint::clearEndpoint(const char* type) } } -void CallEndpoint::setSource(DataSource* source, const char* type) +void CallEndpoint::setSource(DataSource* source, const String& type) { DataEndpoint* dat = source ? setEndpoint(type) : getEndpoint(type); if (dat) dat->setSource(source); } -DataSource* CallEndpoint::getSource(const char* type) const +DataSource* CallEndpoint::getSource(const String& type) const { DataEndpoint* dat = getEndpoint(type); return dat ? dat->getSource() : 0; } -void CallEndpoint::setConsumer(DataConsumer* consumer, const char* type) +void CallEndpoint::setConsumer(DataConsumer* consumer, const String& type) { DataEndpoint* dat = consumer ? setEndpoint(type) : getEndpoint(type); if (dat) dat->setConsumer(consumer); } -DataConsumer* CallEndpoint::getConsumer(const char* type) const +DataConsumer* CallEndpoint::getConsumer(const String& type) const { DataEndpoint* dat = getEndpoint(type); return dat ? dat->getConsumer() : 0; } -bool CallEndpoint::clearData(DataNode* node, const char* type) +bool CallEndpoint::clearData(DataNode* node, const String& type) { - if (null(type) || !node) + if (type.null() || !node) return false; Lock mylock(DataEndpoint::commonMutex()); RefPointer dat = getEndpoint(type); return dat && dat->clearData(node); } +const String& CallEndpoint::audioType() +{ + return s_audioType; +} + static const String s_disconnected("chan.disconnected"); diff --git a/yatephone.h b/yatephone.h index 7a9962be..273c917d 100644 --- a/yatephone.h +++ b/yatephone.h @@ -1210,48 +1210,48 @@ public: * @param type Type of data endpoint: "audio", "video", "text" * @return A pointer to the DataEndpoint object or NULL if not found */ - DataEndpoint* getEndpoint(const char* type = "audio") const; + DataEndpoint* getEndpoint(const String& type = CallEndpoint::audioType()) const; /** * Get a data endpoint of this object, create if required * @param type Type of data endpoint: "audio", "video", "text" * @return A pointer to the DataEndpoint object or NULL if an error occured */ - DataEndpoint* setEndpoint(const char* type = "audio"); + DataEndpoint* setEndpoint(const String& type = CallEndpoint::audioType()); /** * Clear one or all data endpoints of this object * @param type Type of data endpoint: "audio", "video", "text", NULL to clear all */ - void clearEndpoint(const char* type = 0); + void clearEndpoint(const String& type = String::empty()); /** * Set a data source of this object * @param source A pointer to the new source or NULL * @param type Type of data node: "audio", "video", "text" */ - void setSource(DataSource* source = 0, const char* type = "audio"); + void setSource(DataSource* source = 0, const String& type = CallEndpoint::audioType()); /** * Get a data source of this object * @param type Type of data node: "audio", "video", "text" * @return A pointer to the DataSource object or NULL */ - DataSource* getSource(const char* type = "audio") const; + DataSource* getSource(const String& type = CallEndpoint::audioType()) const; /** * Set the data consumer of this object * @param consumer A pointer to the new consumer or NULL * @param type Type of data node: "audio", "video", "text" */ - void setConsumer(DataConsumer* consumer = 0, const char* type = "audio"); + void setConsumer(DataConsumer* consumer = 0, const String& type = CallEndpoint::audioType()); /** * Get the data consumer of this object * @param type Type of data node: "audio", "video", "text" * @return A pointer to the DataConsumer object or NULL */ - DataConsumer* getConsumer(const char* type = "audio") const; + DataConsumer* getConsumer(const String& type = CallEndpoint::audioType()) const; /** * Clear a data node from any slot of a DataEndpoint of this object @@ -1259,7 +1259,13 @@ public: * @param type Type of data node: "audio", "video", "text" * @return True if the node was removed from at least one slot */ - bool clearData(DataNode* node, const char* type = "audio"); + bool clearData(DataNode* node, const String& type = CallEndpoint::audioType()); + + /** + * Return the defaul audio type "audio" + * @return Return a string naming the "audio" type + */ + static const String& audioType(); protected: /**