Commit 0cb75cf5 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#6251: Implement history serialization using a list wether than a map

parent af571461
......@@ -1271,83 +1271,42 @@ void sflphone_fill_conference_list (void)
void sflphone_fill_history (void)
{
GHashTable *entries;
GHashTableIter iter;
gpointer key, value;
gpointer key_to_min = NULL;
gchar **entries, *current_entry;
callable_obj_t *history_entry;
conference_obj_t *conference_entry;
int timestamp = 0;
int min_timestamp = 0;
gchar *value;
gboolean is_first;
DEBUG ("======================================================== SFLphone: Loading history");
DEBUG ("======================================================= SFLphone: Loading history");
entries = dbus_get_history ();
if (entries) {
while (g_hash_table_size (entries)) {
is_first = TRUE;
// find lowest timestamp in map
g_hash_table_iter_init (&iter, entries);
while (g_hash_table_iter_next (&iter, &key, &value)) {
timestamp = atoi ( (gchar*) key);
if (is_first) {
// first iteration of the loop, init search
min_timestamp = timestamp;
key_to_min = key;
is_first = FALSE;
} else {
// if lower, replace
if (timestamp < min_timestamp) {
min_timestamp = timestamp;
key_to_min = key;
}
}
}
if (g_hash_table_lookup_extended (entries, key_to_min, &key, &value)) {
gchar **ptr;
const gchar *delim = "|";
ptr = g_strsplit(value, delim, 6);
if(ptr != NULL) {
// first ptr refers to entry type
if(g_strcmp0(*ptr, "2188") == 0) {
DEBUG("------------------------------- SFLphone: Serialized item: %s", *ptr);
create_conference_history_entry_from_serialized((gchar *)key, (gchar **)ptr, &conference_entry);
conferencelist_add (history, conference_entry);
conferencelist_add(current_calls, conference_entry);
calltree_add_conference (history, conference_entry);
g_hash_table_remove(entries, key_to_min);
}
else {
// do something with key and value
create_history_entry_from_serialized_form ( (gchar*) key, (gchar **) ptr, &history_entry);
while (*entries) {
const gchar *delim = "|";
gchar **ptr;
current_entry = *entries;
ptr = g_strsplit(current_entry, delim, 6);
if(ptr != NULL) {
// first ptr refers to entry type
if(g_strcmp0(*ptr, "2188") == 0) {
DEBUG("------------------------------- SFLphone: Serialized item: %s", *ptr);
create_conference_history_entry_from_serialized(ptr, &conference_entry);
conferencelist_add (history, conference_entry);
conferencelist_add(current_calls, conference_entry);
calltree_add_conference (history, conference_entry);
}
else {
// do something with key and value
create_history_entry_from_serialized_form (ptr, &history_entry);
// Add it and update the GUI
calllist_add_call (history, history_entry);
calltree_add_call (history, history_entry, NULL);
// remove entry from map
g_hash_table_remove (entries, key_to_min);
}
}
}
}
// Add it and update the GUI
calllist_add_call (history, history_entry);
calltree_add_call (history, history_entry, NULL);
}
}
entries++;
}
DEBUG ("======================================================== SFLphone: Loading history ...(end)");
......
......@@ -298,7 +298,7 @@ void create_new_call_from_details (const gchar *call_id, GHashTable *details, ca
*call = new_call;
}
void create_history_entry_from_serialized_form (gchar *timestamp UNUSED, gchar **ptr, callable_obj_t **call)
void create_history_entry_from_serialized_form (gchar **ptr, callable_obj_t **call)
{
gchar *peer_name = "";
gchar *peer_number = "", *accountID = "", *time_start = "", *time_stop = "";
......
......@@ -171,7 +171,7 @@ void create_new_call (callable_type_t, call_state_t, gchar*, gchar*, gchar*, gch
void create_new_call_from_details (const gchar *, GHashTable *, callable_obj_t **);
void create_history_entry_from_serialized_form (gchar *, gchar **, callable_obj_t **);
void create_history_entry_from_serialized_form (gchar **, callable_obj_t **);
void call_add_error (callable_obj_t * call, gpointer dialog);
......
......@@ -252,7 +252,7 @@ gchar *serialize_history_conference_entry(conference_obj_t *entry)
return result;
}
void create_conference_history_entry_from_serialized(gchar *timestamp UNUSED, gchar **ptr, conference_obj_t **conf)
void create_conference_history_entry_from_serialized(gchar **ptr, conference_obj_t **conf)
{
history_state_t history_state = MISSED;
gint token = 0;
......
......@@ -86,6 +86,6 @@ void conference_participant_list_update (gchar**, conference_obj_t*);
gchar *serialize_history_conference_entry(conference_obj_t *entry);
void create_conference_history_entry_from_serialized(gchar *, gchar **, conference_obj_t **);
void create_conference_history_entry_from_serialized(gchar **, conference_obj_t **);
#endif
......@@ -753,7 +753,7 @@
<tp:docstring>
</tp:docstring>
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/>
<arg type="a{ss}" name="entries" direction="out">
<arg type="as" name="entries" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
......@@ -763,7 +763,7 @@
<tp:docstring>
</tp:docstring>
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="MapStringString"/>
<arg type="a{ss}" name="entries" direction="in">
<arg type="as" name="entries" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
......
......@@ -2229,30 +2229,32 @@ dbus_set_accounts_order (const gchar* order)
}
}
GHashTable*
gchar **
dbus_get_history (void)
{
GError *error = NULL;
GHashTable *entries = NULL;
const gchar **entries = NULL;
org_sflphone_SFLphone_ConfigurationManager_get_history (
configurationManagerProxy, &entries, &error);
configurationManagerProxy, (char ***)&entries, &error);
if (error) {
ERROR ("Error calling org_sflphone_SFLphone_CallManager_get_history");
ERROR ("Error calling get history: %s", error->message);
g_error_free (error);
return NULL;
}
return entries;
}
void
dbus_set_history (GHashTable* entries)
dbus_set_history (GSList *entries)
{
GError *error = NULL;
gchar **charlist = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_history (
configurationManagerProxy, entries, &error);
configurationManagerProxy, (const char **)charlist, &error);
if (error) {
ERROR ("Error calling org_sflphone_SFLphone_CallManager_set_history");
......
......@@ -551,9 +551,18 @@ gchar** dbus_get_conference_list (void);
void dbus_set_accounts_order (const gchar* order);
GHashTable* dbus_get_history (void);
/**
* Get a list of serialized hisotry entries
* @return The list of history entries
*/
gchar **dbus_get_history (void);
void dbus_set_history (GHashTable* entries);
/**
* Set the history entries into the daemon. The daemon then write teh content
* of this list into the history file
* @param A list of serialized history entries
*/
void dbus_set_history (GSList *);
void sflphone_display_transfer_status (const gchar* message);
......
......@@ -754,7 +754,7 @@
<tp:docstring>
</tp:docstring>
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="MapStringString"/>
<arg type="a{ss}" name="entries" direction="out">
<arg type="as" name="entries" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
......@@ -764,7 +764,7 @@
<tp:docstring>
</tp:docstring>
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="MapStringString"/>
<arg type="a{ss}" name="entries" direction="in">
<arg type="as" name="entries" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
......
......@@ -790,15 +790,14 @@ void ConfigurationManager::setAccountsOrder (const std::string& order)
Manager::instance().setAccountsOrder (order);
}
std::map<std::string, std::string> ConfigurationManager::getHistory (void)
std::vector<std::string> ConfigurationManager::getHistory (void)
{
return Manager::instance().send_history_to_client();
return Manager::instance().getHistorySerialized();
}
void ConfigurationManager::setHistory (
const std::map<std::string, std::string>& entries)
void ConfigurationManager::setHistory (const std::vector<std::string>& entries)
{
Manager::instance().receive_history_from_client (entries);
Manager::instance().setHistorySerialized(entries);
}
std::string ConfigurationManager::getAddrFromInterfaceName (
......
......@@ -140,8 +140,8 @@ class ConfigurationManager
std::map<std::string, std::string> getHookSettings (void);
void setHookSettings (const std::map<std::string, std::string>& settings);
std::map <std::string, std::string> getHistory (void);
void setHistory (const std::map <std::string, std::string>& entries);
std::vector<std::string> getHistory(void);
void setHistory (const std::vector<std::string> &entries);
std::map<std::string, std::string> getTlsSettings (void);
void setTlsSettings (const std::map< std::string, std::string >& details);
......
......@@ -50,8 +50,7 @@ HistoryItem::HistoryItem (std::string timestamp_start, CallType call_type, std::
}
HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
: _timestamp_start (timestamp)
HistoryItem::HistoryItem (std::string serialized_form)
{
size_t pos;
std::string tmp, id, name, number, start, stop, account, recordFile;
......@@ -69,26 +68,26 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
break;
case 1: // The number field
number = tmp;
_error("Unserialized number: %s", tmp.c_str());
_error("Serialized number: %s", tmp.c_str());
break;
case 2: // The name field
name = tmp;
_error("Unserialized name: %s", tmp.c_str());
_error("Serialized name: %s", tmp.c_str());
break;
case 3: // The start timestamp
_error("Unserialized time start: %s", tmp.c_str());
_error("Serialized time start: %s", tmp.c_str());
start = tmp;
break;
case 4: // The end timestamp
_error("Unserialized time stop: %s", tmp.c_str());
_error("Serialized time stop: %s", tmp.c_str());
stop = tmp;
break;
case 5: // The account ID
_error("Unserialized account: %s", tmp.c_str());
_error("Serialized account: %s", tmp.c_str());
account = tmp;
break;
case 6: // The recorded file name
_error("Unserialized recordfile: %s", tmp.c_str());
_error("Serialized recordfile: %s", tmp.c_str());
recordFile = tmp;
break;
default: // error
......@@ -103,6 +102,7 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
_number = number;
(name == EMPTY_STRING) ? _name = "" : _name = name;
_timestamp_start = start;
_timestamp_stop = stop;
(serialized_form == EMPTY_STRING) ? _account_id = "" : _account_id=tmp;
}
......@@ -123,6 +123,14 @@ bool HistoryItem::save (Conf::ConfigTree **history)
section = get_timestamp ();
call_type << _call_type;
_error("Unserialized type: %s", call_type.str().c_str());
_error("Unserialized time start: %s", _timestamp_start.c_str());
_error("Unserialized time stop: %s", _timestamp_stop.c_str());
_error("Unserialized number: %s", _number.c_str());
_error("Unserialized account: %s", _account_id.c_str());
_error("Unserialized name: %s", _name.c_str());
_error("Unserialized record file: %s", _recording_file.c_str());
res = ( (*history)->setConfigTreeItem (section, "type", call_type.str())
&& (*history)->setConfigTreeItem (section, "timestamp_start", _timestamp_start)
&& (*history)->setConfigTreeItem (section, "timestamp_stop", _timestamp_stop)
......
......@@ -63,8 +63,9 @@ class HistoryItem
/*
* Constructor from a serialized form
* @string contaning serialized form
*/
HistoryItem (std::string, std::string="");
HistoryItem (std::string="");
/*
* Destructor
......
......@@ -49,7 +49,7 @@ HistoryManager::~HistoryManager ()
HistoryItem * item;
while (iter != _history_items.end()) {
item = iter->second;
item = *iter;
delete item;
iter++;
}
......@@ -113,13 +113,19 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list, int
while (iter != sections.end()) {
type = (CallType) getConfigInt (*iter, "type", history_list);
timestamp_start = getConfigString (*iter, "timestamp_start", history_list);
timestamp_stop = getConfigString (*iter, "timestamp_stop", history_list);
name = getConfigString (*iter, "name", history_list);
number = getConfigString (*iter, "number", history_list);
accountID = getConfigString (*iter, "accountid", history_list);
recording_file = getConfigString(*iter, "recordfile", history_list);
timestamp_start = *iter;
_error("Unserialized time start: %s", timestamp_start.c_str());
_error("Unserialized time stop: %s", timestamp_stop.c_str());
_error("Unserialized number: %s", number.c_str());
_error("Unserialized account: %s", accountID.c_str());
_error("Unserialized name: %s", name.c_str());
_error("Unserialized record file: %s", recording_file.c_str());
// Make a check on the start timestamp to know it is loadable according to CONFIG_HISTORY_LIMIT
......@@ -138,7 +144,7 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list, int
bool HistoryManager::save_history_to_file (Conf::ConfigTree *history_list)
{
_debug ("Saving history in XDG directory: %s", _history_path.data());
_debug ("HistoryManager: Saving history in XDG directory: %s", _history_path.data());
return history_list->saveConfigTree (_history_path.data());
}
......@@ -152,7 +158,7 @@ int HistoryManager::save_history_items_map (Conf::ConfigTree *history_list)
iter = _history_items.begin ();
while (iter != _history_items.end ()) {
item = iter->second;
item = *iter;
if (item) {
if (item->save (&history_list))
......@@ -170,7 +176,7 @@ int HistoryManager::save_history_items_map (Conf::ConfigTree *history_list)
void HistoryManager::add_new_history_entry (HistoryItem *new_item)
{
// Add it in the map
_history_items [new_item->get_timestamp () ] = new_item;
_history_items.push_back(new_item);
}
int HistoryManager::create_history_path (std::string path)
......@@ -194,7 +200,7 @@ int HistoryManager::create_history_path (std::string path)
if (mkdir (userdata.data(), 0755) != 0) {
// If directory creation failed
if (errno != EEXIST) {
_debug ("Cannot create directory: %s", strerror (errno));
_debug ("HistoryManager: Cannot create directory: %s", strerror (errno));
return -1;
}
}
......@@ -233,22 +239,22 @@ HistoryManager::getConfigString (const std::string& section, const std::string&
return "";
}
std::map <std::string, std::string> HistoryManager::get_history_serialized (void)
std::vector<std::string> HistoryManager::get_history_serialized (void)
{
std::map <std::string, std::string> serialized;
std::vector<std::string> serialized;
HistoryItemMap::iterator iter;
HistoryItem *current;
std::string res, key;
std::string res;
iter = _history_items.begin ();
while (iter != _history_items.end()) {
current = iter->second;
current = *iter;
if (current) {
key = current->get_timestamp ();
res = current->serialize ();
serialized [key] = res;
_error("%s", res.c_str());
serialized.push_back(res);
}
iter ++;
......@@ -258,9 +264,9 @@ std::map <std::string, std::string> HistoryManager::get_history_serialized (void
}
int HistoryManager::set_serialized_history (std::map <std::string, std::string> history, int limit)
int HistoryManager::set_serialized_history (std::vector<std::string> history, int limit)
{
std::map <std::string, std::string>::iterator iter;
std::vector<std::string>::iterator iter;
HistoryItem *new_item;
int items_added = 0;
int history_limit;
......@@ -276,11 +282,18 @@ int HistoryManager::set_serialized_history (std::map <std::string, std::string>
iter = history.begin ();
while (iter != history.end ()) {
if (atoi (iter->first.c_str ()) >= ( (int) current_timestamp - history_limit)) {
new_item = new HistoryItem (iter->first, iter->second);
new_item = new HistoryItem(*iter);
if(new_item == NULL) {
_error("HistoryManager: Error: Could not create history item");
}
int item_timestamp = atoi(new_item->get_timestamp().c_str());
if (item_timestamp >= ( (int) current_timestamp - history_limit)) {
add_new_history_entry (new_item);
items_added ++;
}
else {
delete new_item;
}
iter ++;
}
......
......@@ -39,7 +39,7 @@
#define DAY_UNIX_TIMESTAMP 86400 // Number of seconds in one day: 60 x 60 x 24
typedef std::map <std::string, HistoryItem*> HistoryItemMap;
typedef std::vector <HistoryItem *> HistoryItemMap;
class HistoryManager
{
......@@ -105,9 +105,9 @@ class HistoryManager
return _history_items.size ();
}
std::map <std::string, std::string> get_history_serialized (void);
std::vector<std::string> get_history_serialized (void);
int set_serialized_history (std::map <std::string, std::string> history, int limit);
int set_serialized_history (std::vector<std::string> history, int limit);
private:
int get_unix_timestamp_equivalent (int days) const {
......
......@@ -4560,15 +4560,18 @@ std::map<std::string, std::string> ManagerImpl::getCallDetails (const CallID& ca
return call_details;
}
std::map<std::string, std::string> ManagerImpl::send_history_to_client (void)
std::vector<std::string> ManagerImpl::getHistorySerialized(void)
{
_debug("Manager: Get history serialized");
return _history->get_history_serialized();
}
void ManagerImpl::receive_history_from_client (std::map<std::string,
std::string> history)
void ManagerImpl::setHistorySerialized(std::vector<std::string> history)
{
_debug("Manager: Set history serialized");
_history->set_serialized_history (history, preferences.getHistoryLimit());;
_history->save_history();
}
......
......@@ -1426,9 +1426,17 @@ class ManagerImpl
*/
bool accountExists (const AccountID& accountID);
std::map<std::string, std::string> send_history_to_client (void);
/**
* Get a list of serialized history entries
* @return A list of serialized entry
*/
std::vector<std::string> getHistorySerialized (void);
void receive_history_from_client (std::map<std::string, std::string> history);
/**
* Set a list of serialized history entries
* @param Vector of history entries
*/
void setHistorySerialized (std::vector<std::string> history);
/**
* Get an account pointer
* @param accountID account ID to get
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment