diff --git a/include/linphone/utils/general.h b/include/linphone/utils/general.h index b11044e92..495d72ee1 100644 --- a/include/linphone/utils/general.h +++ b/include/linphone/utils/general.h @@ -93,14 +93,28 @@ class ObjectPrivate; friend class CLASS ## Private; \ friend class Wrapper; +#define L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ + inline CLASS ## Private *getPrivate() { \ + return reinterpret_cast(PARENT_TYPE::mPrivate); \ + } \ + inline const CLASS ## Private *getPrivate() const { \ + return reinterpret_cast(PARENT_TYPE::mPrivate); \ + } \ + friend class CLASS ## Private; \ + friend class Wrapper; + // Allows access to private internal data. // Gives a control to C Wrapper. #ifndef LINPHONE_TESTER #define L_DECLARE_PRIVATE(CLASS) L_INTERNAL_DECLARE_PRIVATE(CLASS) + #define L_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) #else #define L_DECLARE_PRIVATE(CLASS) \ L_INTERNAL_DECLARE_PRIVATE(CLASS) \ friend class Tester; + #define L_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ + L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ + friend class Tester; #endif template diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 080df4c96..8bf3bbf28 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,8 +24,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES address/address-p.h address/address.h c-wrapper/c-wrapper.h - c-wrapper/internal/c-tools.h c-wrapper/internal/c-sal.h + c-wrapper/internal/c-tools.h call/call-listener.h call/call-p.h call/call.h @@ -55,18 +55,18 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES chat/real-time-text-chat-room.h conference/conference-listener.h conference/conference.h - conference/local-conference.h conference/local-conference-event-handler-p.h conference/local-conference-event-handler.h + conference/local-conference.h conference/params/call-session-params-p.h conference/params/call-session-params.h conference/params/media-session-params-p.h conference/params/media-session-params.h conference/participant-p.h conference/participant.h - conference/remote-conference.h conference/remote-conference-event-handler-p.h conference/remote-conference-event-handler.h + conference/remote-conference.h conference/session/call-session-listener.h conference/session/call-session-p.h conference/session/call-session.h @@ -93,6 +93,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES logger/logger.h nat/ice-agent.h nat/stun-client.h + object/app-data-container.h object/clonable-object-p.h object/clonable-object.h object/object-p.h @@ -110,14 +111,14 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES set(LINPHONE_CXX_OBJECTS_SOURCE_FILES address/address.cpp c-wrapper/api/c-address.cpp - c-wrapper/api/c-call.cpp c-wrapper/api/c-call-cbs.cpp c-wrapper/api/c-call-params.cpp c-wrapper/api/c-call-stats.cpp - c-wrapper/api/c-chat-message.cpp + c-wrapper/api/c-call.cpp c-wrapper/api/c-chat-message-cbs.cpp - c-wrapper/api/c-chat-room.cpp + c-wrapper/api/c-chat-message.cpp c-wrapper/api/c-chat-room-cbs.cpp + c-wrapper/api/c-chat-room.cpp c-wrapper/api/c-event-log.cpp c-wrapper/api/c-participant.cpp c-wrapper/internal/c-sal.cpp @@ -139,13 +140,13 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES chat/modifier/multipart-chat-message-modifier.cpp chat/real-time-text-chat-room.cpp conference/conference.cpp - conference/local-conference.cpp conference/local-conference-event-handler.cpp + conference/local-conference.cpp conference/params/call-session-params.cpp conference/params/media-session-params.cpp conference/participant.cpp - conference/remote-conference.cpp conference/remote-conference-event-handler.cpp + conference/remote-conference.cpp conference/session/call-session.cpp conference/session/media-session.cpp content/content-type.cpp @@ -164,6 +165,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES logger/logger.cpp nat/ice-agent.cpp nat/stun-client.cpp + object/app-data-container.cpp object/clonable-object.cpp object/object.cpp object/property-container.cpp @@ -172,9 +174,9 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES sal/message-op.cpp sal/op.cpp sal/presence-op.cpp + sal/refer-op.cpp sal/register-op.cpp sal/sal.cpp - sal/refer-op.cpp utils/general.cpp utils/payload-type-handler.cpp utils/utils.cpp diff --git a/src/content/content.cpp b/src/content/content.cpp index b9581de73..e8d12d176 100644 --- a/src/content/content.cpp +++ b/src/content/content.cpp @@ -39,7 +39,7 @@ public: Content::Content () : ClonableObject(*new ContentPrivate) {} -Content::Content (const Content &src) : ClonableObject(*new ContentPrivate) { +Content::Content (const Content &src) : ClonableObject(*new ContentPrivate), AppDataContainer() { L_D(); d->body = src.getBody(); d->contentType = src.getContentType(); diff --git a/src/content/content.h b/src/content/content.h index 57f78787f..1e547ddf1 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -23,6 +23,7 @@ #include #include "content-type.h" +#include "object/app-data-container.h" #include "object/clonable-object.h" // ============================================================================= @@ -31,7 +32,7 @@ LINPHONE_BEGIN_NAMESPACE class ContentPrivate; -class LINPHONE_PUBLIC Content : public ClonableObject { +class LINPHONE_PUBLIC Content : public ClonableObject, public AppDataContainer { public: Content (); Content (const Content &src); @@ -63,7 +64,7 @@ public: bool isEmpty () const; private: - L_DECLARE_PRIVATE(Content); + L_DECLARE_PRIVATE_T(Content, ClonableObject); }; LINPHONE_END_NAMESPACE diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 0f27f8e61..16af86e41 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -509,7 +509,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} return false; } - int &id = const_cast(eventLog).getPrivate()->id; + long &id = const_cast(eventLog).getPrivate()->id; if (id < 0) return false; diff --git a/src/event-log/event-log-p.h b/src/event-log/event-log-p.h index 17aa3ee1a..7e7a7788b 100644 --- a/src/event-log/event-log-p.h +++ b/src/event-log/event-log-p.h @@ -29,7 +29,7 @@ LINPHONE_BEGIN_NAMESPACE class EventLogPrivate : public ClonableObjectPrivate { public: - int id = -1; + long id = -1; private: EventLog::Type type = EventLog::Type::None; diff --git a/src/object/app-data-container.cpp b/src/object/app-data-container.cpp new file mode 100644 index 000000000..37f33801b --- /dev/null +++ b/src/object/app-data-container.cpp @@ -0,0 +1,68 @@ +/* + * app-data-container.cpp + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "app-data-container.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class AppDataContainerPrivate { +public: + unordered_map appData; +}; + +// ----------------------------------------------------------------------------- + +AppDataContainer::AppDataContainer () : mPrivate(new AppDataContainerPrivate) {} + +// Empty copy constructor. Don't change this pattern. +// AppDataContainer is an Entity component, not a simple structure. +// An Entity is UNIQUE. +AppDataContainer::AppDataContainer (const AppDataContainer &) : mPrivate(new AppDataContainerPrivate) {} + +AppDataContainer::~AppDataContainer () { + delete mPrivate; +} + +AppDataContainer &AppDataContainer::operator= (const AppDataContainer &) { + return *this; +} + +string AppDataContainer::getAppData (const string &name) const { + L_D(); + auto it = d->appData.find(name); + return it == d->appData.cend() ? string() : it->second; +} + +void AppDataContainer::setAppData (const string &name, const string &appData) { + L_D(); + d->appData[name] = appData; +} + +void AppDataContainer::setAppData (const string &name, string &&appData) { + L_D(); + d->appData[name] = move(appData); +} + +LINPHONE_END_NAMESPACE diff --git a/src/object/app-data-container.h b/src/object/app-data-container.h new file mode 100644 index 000000000..274e5acbd --- /dev/null +++ b/src/object/app-data-container.h @@ -0,0 +1,53 @@ +/* + * app-data-container.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _APP_DATA_CONTAINER_H_ +#define _APP_DATA_CONTAINER_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class AppDataContainerPrivate; + +class LINPHONE_PUBLIC AppDataContainer { +public: + AppDataContainer (); + AppDataContainer (const AppDataContainer &src); + virtual ~AppDataContainer (); + + AppDataContainer &operator= (const AppDataContainer &src); + + std::string getAppData (const std::string &name) const; + void setAppData (const std::string &name, const std::string &appData); + void setAppData (const std::string &name, std::string &&appData); + +private: + AppDataContainerPrivate *mPrivate = nullptr; + + L_DECLARE_PRIVATE(AppDataContainer); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _APP_DATA_CONTAINER_H_