From f9a078befa2a8a4a74c2581428a3d534db51dedd Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 18 Aug 2017 13:13:11 +0200 Subject: [PATCH] feat(Event): provide a working call event --- CMakeLists.txt | 9 +++++- coreapi/help/examples/C/buddy_status.c | 4 +-- coreapi/help/examples/C/chatroom.c | 4 +-- coreapi/help/examples/C/filetransfer.c | 4 +-- coreapi/help/examples/C/helloworld.c | 2 +- coreapi/help/examples/C/notify.c | 4 +-- .../help/examples/C/realtimetext_receiver.c | 2 +- coreapi/help/examples/C/realtimetext_sender.c | 2 +- coreapi/help/examples/C/registration.c | 2 +- src/CMakeLists.txt | 1 + src/event/call-event.cpp | 28 ++++++++++++++++- src/event/call-event.h | 6 +++- src/event/event.cpp | 4 +-- src/event/message-event.cpp | 2 +- src/logger/logger.cpp | 4 ++- src/utils/general.cpp | 31 +++++++++++++++++++ src/utils/general.h | 12 +++++-- 17 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 src/utils/general.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1283185a3..83c390b2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,13 @@ cmake_dependent_option(ENABLE_ASSISTANT "Turn on assistant compiling." YES "ENAB set(CMAKE_CXX_STANDARD 11) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG") + if(ENABLE_STATIC) set(LINPHONE_LIBS_FOR_TOOLS linphone-static) else() @@ -259,7 +266,7 @@ if(LINPHONE_CPPFLAGS) endif() if(ENABLE_DEBUG_LOGS) - add_definitions("-DDEBUG") + add_definitions("-DDEBUG_LOGS") endif() set(STRICT_OPTIONS_CPP ) diff --git a/coreapi/help/examples/C/buddy_status.c b/coreapi/help/examples/C/buddy_status.c index 905162214..98149b951 100644 --- a/coreapi/help/examples/C/buddy_status.c +++ b/coreapi/help/examples/C/buddy_status.c @@ -107,8 +107,8 @@ int main(int argc, char *argv[]){ password=argv[3]; } signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/chatroom.c b/coreapi/help/examples/C/chatroom.c index 52a71faab..ad21d3399 100644 --- a/coreapi/help/examples/C/chatroom.c +++ b/coreapi/help/examples/C/chatroom.c @@ -59,8 +59,8 @@ int main(int argc, char *argv[]){ } signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/filetransfer.c b/coreapi/help/examples/C/filetransfer.c index e461aafa2..485c0a662 100644 --- a/coreapi/help/examples/C/filetransfer.c +++ b/coreapi/help/examples/C/filetransfer.c @@ -133,8 +133,8 @@ int main(int argc, char *argv[]){ big_file[sizeof(big_file)-1]=*"E"; signal(SIGINT,stop); -//#define DEBUG -#ifdef DEBUG +//#define DEBUG_LOGS +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif vtable.message_received=message_received; diff --git a/coreapi/help/examples/C/helloworld.c b/coreapi/help/examples/C/helloworld.c index 19f433eab..8da3b227f 100644 --- a/coreapi/help/examples/C/helloworld.c +++ b/coreapi/help/examples/C/helloworld.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/notify.c b/coreapi/help/examples/C/notify.c index 8ebbc3e82..9f20cdb1c 100644 --- a/coreapi/help/examples/C/notify.c +++ b/coreapi/help/examples/C/notify.c @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#define DEBUG 1 +#define DEBUG_LOGS 1 #include "linphone/core.h" @@ -102,7 +102,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/realtimetext_receiver.c b/coreapi/help/examples/C/realtimetext_receiver.c index 9d8acf5dc..3915749a8 100644 --- a/coreapi/help/examples/C/realtimetext_receiver.c +++ b/coreapi/help/examples/C/realtimetext_receiver.c @@ -82,7 +82,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/coreapi/help/examples/C/realtimetext_sender.c b/coreapi/help/examples/C/realtimetext_sender.c index d765a6768..340ad7de2 100644 --- a/coreapi/help/examples/C/realtimetext_sender.c +++ b/coreapi/help/examples/C/realtimetext_sender.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif diff --git a/coreapi/help/examples/C/registration.c b/coreapi/help/examples/C/registration.c index 318723323..66667bc05 100644 --- a/coreapi/help/examples/C/registration.c +++ b/coreapi/help/examples/C/registration.c @@ -76,7 +76,7 @@ int main(int argc, char *argv[]){ signal(SIGINT,stop); -#ifdef DEBUG +#ifdef DEBUG_LOGS linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 523a270f4..422c8b1f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES message/message.cpp object/clonable-object.cpp object/object.cpp + utils/general.cpp utils/utils.cpp ) diff --git a/src/event/call-event.cpp b/src/event/call-event.cpp index 5620cb303..3837e9f9f 100644 --- a/src/event/call-event.cpp +++ b/src/event/call-event.cpp @@ -16,8 +16,34 @@ * along with this program. If not, see . */ +#include "event-p.h" + #include "call-event.h" // ============================================================================= -// TODO. +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +class CallEventPrivate : public EventPrivate { +public: + shared_ptr call; +}; + +// ----------------------------------------------------------------------------- + +CallEvent::CallEvent (Type type, const shared_ptr &call) : Event(*new CallEventPrivate, type) { + L_D(CallEvent); + L_ASSERT(call); + d->call = call; +} + +CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getCall()) {} + +shared_ptr CallEvent::getCall () const { + L_D(const CallEvent); + return d->call; +} + +LINPHONE_END_NAMESPACE diff --git a/src/event/call-event.h b/src/event/call-event.h index 044946fce..fa2577aea 100644 --- a/src/event/call-event.h +++ b/src/event/call-event.h @@ -19,6 +19,8 @@ #ifndef _CALL_EVENT_H_ #define _CALL_EVENT_H_ +#include + #include "event.h" // ============================================================================= @@ -30,9 +32,11 @@ class CallEventPrivate; class LINPHONE_PUBLIC CallEvent : public Event { public: - CallEvent (const Call &message); + CallEvent (Type type, const std::shared_ptr &message); CallEvent (const CallEvent &src); + std::shared_ptr getCall () const; + private: L_DECLARE_PRIVATE(CallEvent); }; diff --git a/src/event/event.cpp b/src/event/event.cpp index 6a059950f..af505a417 100644 --- a/src/event/event.cpp +++ b/src/event/event.cpp @@ -26,9 +26,7 @@ LINPHONE_BEGIN_NAMESPACE Event::Event () : ClonableObject(*new EventPrivate) {} -Event::Event (const Event &) : ClonableObject(*new EventPrivate) { - // `src` parameter is useless. -} +Event::Event (const Event &) : ClonableObject(*new EventPrivate) {} Event::Event (EventPrivate &p, Type type) : ClonableObject(p) { L_D(Event); diff --git a/src/event/message-event.cpp b/src/event/message-event.cpp index f9ca6fa62..84c140526 100644 --- a/src/event/message-event.cpp +++ b/src/event/message-event.cpp @@ -17,7 +17,6 @@ */ #include "event-p.h" -#include "message/message.h" #include "message-event.h" @@ -36,6 +35,7 @@ public: MessageEvent::MessageEvent (const shared_ptr &message) : Event(*new MessageEventPrivate, Event::MessageEvent) { L_D(MessageEvent); + L_ASSERT(message); d->message = message; } diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index 340cf4a4f..7ca01589d 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -49,7 +49,9 @@ Logger::~Logger () { switch (d->level) { case Debug: - ms_debug("%s", str.c_str()); + #if DEBUG_LOGS + ms_debug("%s", str.c_str()); + #endif // if DEBUG_LOGS break; case Info: ms_message("%s", str.c_str()); diff --git a/src/utils/general.cpp b/src/utils/general.cpp new file mode 100644 index 000000000..9ed357c03 --- /dev/null +++ b/src/utils/general.cpp @@ -0,0 +1,31 @@ +/* + * general.cpp + * Copyright (C) 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 3 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, see . + */ + +#include "logger/logger.h" + +#include "general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +void l_assert (const char *condition, const char *file, int line) { + lFatal() << "ASSERT: " << condition << " in " << file << " line " << line << "."; +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/general.h b/src/utils/general.h index 41eac6087..b91bf5af0 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -// ============================================================================= - #ifndef _GENERAL_H_ #define _GENERAL_H_ +// ============================================================================= + #define LINPHONE_NAMESPACE LinphonePrivate #define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { #define LINPHONE_END_NAMESPACE } @@ -72,6 +72,14 @@ LINPHONE_BEGIN_NAMESPACE #define L_D(CLASS) CLASS ## Private * const d = getPrivate(); #define L_Q(CLASS) CLASS * const q = getPublic(); +void l_assert (const char *condition, const char *file, int line); + +#ifdef DEBUG + #define L_ASSERT(CONDITION) static_cast(false && (CONDITION)) +#else + #define L_ASSERT(CONDITION) ((CONDITION) ? static_cast(0) : l_assert(#CONDITION, __FILE__, __LINE__)) +#endif + LINPHONE_END_NAMESPACE #endif // ifndef _GENERAL_H_