From 73f4cc71ad10c19c12fe2ffd05e7d674dce38359 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou Date: Fri, 29 May 2009 14:19:01 -0400 Subject: [PATCH] [#1214] History integration in build system; unit test squeleton --- sflphone-common/configure.ac | 3 +- sflphone-common/globals.mak | 1 + sflphone-common/src/Makefile.am | 5 +-- sflphone-common/src/history/Makefile.am | 5 +-- sflphone-common/src/history/historyitem.cpp | 2 +- sflphone-common/src/history/historyitem.h | 8 +++-- .../src/history/historymanager.cpp | 32 +++++++++++++++++-- sflphone-common/src/history/historymanager.h | 24 +++++++++++++- sflphone-common/test/Makefile.am | 24 ++++++++++++-- 9 files changed, 90 insertions(+), 14 deletions(-) diff --git a/sflphone-common/configure.ac b/sflphone-common/configure.ac index c2c254719..15d393d98 100644 --- a/sflphone-common/configure.ac +++ b/sflphone-common/configure.ac @@ -53,7 +53,8 @@ AC_CONFIG_FILES([src/Makefile \ src/plug-in/audiorecorder/Makefile \ src/plug-in/Makefile \ src/plug-in/test/Makefile \ - src/hooks/Makefile]) + src/hooks/Makefile \ + src/history/Makefile]) dnl Unitary test section AC_CONFIG_FILES([test/Makefile]) diff --git a/sflphone-common/globals.mak b/sflphone-common/globals.mak index 37607028c..fa19f77b6 100644 --- a/sflphone-common/globals.mak +++ b/sflphone-common/globals.mak @@ -47,6 +47,7 @@ AM_CPPFLAGS = \ -I$(src)/libs/iax2 \ -I$(src)/libs/pjproject-1.0.1 \ -I$(src)/src \ + -I$(src)/src/config \ -I$(src)/test \ -DPREFIX=\"$(prefix)\" \ -DPROGSHAREDIR=\"${datadir}/sflphone\" \ diff --git a/sflphone-common/src/Makefile.am b/sflphone-common/src/Makefile.am index c3037e329..7a4db6ab7 100644 --- a/sflphone-common/src/Makefile.am +++ b/sflphone-common/src/Makefile.am @@ -13,7 +13,7 @@ IAXSOURCES = IAXHEADERS = endif -SUBDIRS = dbus audio config plug-in hooks +SUBDIRS = dbus audio config plug-in hooks history # Add here the cpp files to be build with sflphone sflphoned_SOURCES = \ @@ -84,6 +84,7 @@ libsflphone_la_LIBADD = \ ./config/libconfig.la \ ./plug-in/libplugin.la \ ./plug-in/audiorecorder/libaudiorecorder.la \ - ./hooks/libhooks.la + ./hooks/libhooks.la \ + ./history/libhistory.la libsflphone_la_SOURCES = diff --git a/sflphone-common/src/history/Makefile.am b/sflphone-common/src/history/Makefile.am index 9be586615..843782642 100644 --- a/sflphone-common/src/history/Makefile.am +++ b/sflphone-common/src/history/Makefile.am @@ -1,3 +1,5 @@ +include ../../globals.mak + SUBDIRS = noinst_LTLIBRARIES = libhistory.la @@ -6,5 +8,4 @@ libhistory_la_SOURCES = \ historyitem.h \ historyitem.cpp \ historymanager.h \ - historymanager.cpp \ - + historymanager.cpp diff --git a/sflphone-common/src/history/historyitem.cpp b/sflphone-common/src/history/historyitem.cpp index d3424e70c..5396b107f 100644 --- a/sflphone-common/src/history/historyitem.cpp +++ b/sflphone-common/src/history/historyitem.cpp @@ -20,7 +20,7 @@ #include -HistoryItem::HistoryItem (int timestamp, CallType call_type, std::string peer, AccountID account_id) +HistoryItem::HistoryItem (int timestamp, CallType call_type, std::string peer, std::string account_id) { // TODO } diff --git a/sflphone-common/src/history/historyitem.h b/sflphone-common/src/history/historyitem.h index 19f46b344..38bbd033b 100644 --- a/sflphone-common/src/history/historyitem.h +++ b/sflphone-common/src/history/historyitem.h @@ -21,7 +21,9 @@ #ifndef _HISTORY_ITEM #define _HISTORY_ITEM -typedef struct { +#include + +typedef enum CallType { CALL_MISSED, CALL_INCOMING, CALL_OUTGOING @@ -34,7 +36,7 @@ class HistoryItem { /* * Constructor */ - HistoryItem (int, CallType, std::string, AccountID = ""); + HistoryItem (int, CallType, std::string, std::string=""); /* * Destructor @@ -63,7 +65,7 @@ class HistoryItem { /* * The account the call was made with */ - AccountID _account_id; + std::string _account_id; }; diff --git a/sflphone-common/src/history/historymanager.cpp b/sflphone-common/src/history/historymanager.cpp index 7b5d505b9..38e1fa180 100644 --- a/sflphone-common/src/history/historymanager.cpp +++ b/sflphone-common/src/history/historymanager.cpp @@ -19,9 +19,19 @@ */ #include +#include +#include HistoryManager::HistoryManager () { - // TODO + + bool exist; + + // Load the path to the file + if (create_history_path () ==1){ + exist = _history_config.populateFromFile (_history_path); + } + + _history_loaded = (exist == 2 ) ? false : true; } HistoryManager::~HistoryManager () { @@ -30,7 +40,7 @@ HistoryManager::~HistoryManager () { int HistoryManager::load_history_from_file (void) { - // TODO + // return 0; } @@ -45,3 +55,21 @@ void HistoryManager::add_new_history_entry (HistoryItem new_item) // TODO } +int HistoryManager::create_history_path (void) { + + std::string path; + + path = std::string(HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR; + + if (mkdir (path.data(), 0755) != 0) { + // If directory creation failed + if (errno != EEXIST) { + _debug("Cannot create directory: %s\n", strerror(errno)); + return -1; + } + } + + // Load user's history + _history_path = path + DIR_SEPARATOR_STR + "history"; + return 0; +} diff --git a/sflphone-common/src/history/historymanager.h b/sflphone-common/src/history/historymanager.h index a7a90fbbf..8e7c3fa31 100644 --- a/sflphone-common/src/history/historymanager.h +++ b/sflphone-common/src/history/historymanager.h @@ -21,7 +21,10 @@ #ifndef _HISTORY_MANAGER #define _HISTORY_MANAGER -#include +#include "historyitem.h" +#include +#include +#include typedef std::map HistoryItemMap; @@ -49,6 +52,10 @@ class HistoryManager { int save_history_to_file (void); private: + /* + * Set the path to the history file + */ + int create_history_path (void); /* * Add a new history item in the data structure */ @@ -59,6 +66,21 @@ class HistoryManager { */ HistoryItemMap _history_items; + /* + * The path to the history file + */ + + std::string _history_path; + + /* + * History has been loaded + */ + bool _history_loaded; + + /* + * The history tree. It contains the call history + */ + Conf::ConfigTree _history_config; }; #endif //_HISTORY_MANAGER diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index d44914c98..72a2003cf 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -1,6 +1,6 @@ include ../globals.mak -bin_PROGRAMS = numbercleanerTester pluginmanagerTester hookmanagerTester audiolayerTester rtpTester +bin_PROGRAMS = numbercleanerTester pluginmanagerTester hookmanagerTester audiolayerTester rtpTester historyTester OBJECT_FILES= \ ../src/sflphoned-managerimpl.o \ @@ -20,7 +20,8 @@ OBJECT_FILES= \ ../src/sflphoned-samplerateconverter.o \ ../src/sflphoned-sdp.o \ ../src/sflphoned-sdpmedia.o \ - ../src/sflphoned-numbercleaner.o + ../src/sflphoned-numbercleaner.o \ + ../src/history/historymanager.o numbercleanerTester_SOURCES = \ numbercleanerTest.h \ @@ -116,3 +117,22 @@ rtpTester_LDADD = \ -luuid \ $(OBJECT_FILES) +historyTester_SOURCES = \ + historyTest.h \ + historyTest.cpp \ + TestMain.cpp + +historyTester_LDADD = \ + ../src/libsflphone.la \ + $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ + @ALSA_LIBS@ \ + @PULSEAUDIO_LIBS@ \ + @CPPUNIT_LIBS@ \ + @CCEXT2_LIBS@ \ + @CCGNU2_LIBS@ \ + @CCRTP_LIBS@ \ + @SAMPLERATE_LIBS@ \ + $(PJSIP_LIBS) \ + -luuid \ + $(OBJECT_FILES) +