Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
67051db1
Commit
67051db1
authored
Oct 17, 2011
by
Tristan Matthews
Browse files
* #7178: create history items on the stack
parent
8d7a5111
Changes
4
Hide whitespace changes
Inline
Side-by-side
daemon/src/history/historyitem.cpp
View file @
67051db1
...
...
@@ -53,14 +53,14 @@ HistoryItem::HistoryItem(std::string timestamp_start, CallType call_type, std::s
HistoryItem
::
HistoryItem
(
std
::
string
serialized_form
)
{
int
ind
ic
e
=
0
;
int
inde
x
=
0
;
while
(
serialized_form
.
find
(
ITEM_SEPARATOR
,
0
)
!=
std
::
string
::
npos
)
{
size_t
pos
=
serialized_form
.
find
(
ITEM_SEPARATOR
,
0
);
std
::
string
tmp
=
serialized_form
.
substr
(
0
,
pos
);
serialized_form
.
erase
(
0
,
pos
+
1
);
switch
(
ind
ic
e
)
{
switch
(
inde
x
)
{
case
0
:
// The call type
call_type_
=
(
CallType
)
atoi
(
tmp
.
c_str
());
break
;
...
...
@@ -91,15 +91,15 @@ HistoryItem::HistoryItem(std::string serialized_form)
case
8
:
// The conference ID
confID_
=
tmp
;
break
;
case
9
:
//
T
he time
case
9
:
//
t
he time
timeAdded_
=
tmp
;
break
;
default:
// error
ERROR
(
"Unserialized form %d not recognized
\n
"
,
ind
ic
e
);
ERROR
(
"Unserialized form %d not recognized
\n
"
,
inde
x
);
break
;
}
ind
ice
++
;
++
ind
ex
;
}
}
...
...
@@ -125,7 +125,7 @@ bool HistoryItem::save(Conf::ConfigTree **history)
&&
(
*
history
)
->
setConfigTreeItem
(
sectionstr
,
"timeadded"
,
timeAdded_
);
}
std
::
string
HistoryItem
::
serialize
()
std
::
string
HistoryItem
::
serialize
()
const
{
// Replace empty string with a valid standard string value
std
::
string
name
(
name_
);
...
...
@@ -149,7 +149,7 @@ std::string HistoryItem::serialize()
}
bool
HistoryItem
::
valid_account
(
std
::
string
id
)
bool
HistoryItem
::
valid_account
(
const
std
::
string
&
id
)
const
{
return
Manager
::
instance
().
accountExists
(
id
);
}
daemon/src/history/historyitem.h
View file @
67051db1
...
...
@@ -73,13 +73,13 @@ class HistoryItem {
bool
save
(
Conf
::
ConfigTree
**
history
);
std
::
string
serialize
();
std
::
string
serialize
()
const
;
private:
/*
* @return true if the account ID corresponds to a loaded account
*/
bool
valid_account
(
std
::
string
)
;
bool
valid_account
(
const
std
::
string
&
id
)
const
;
/*
* Timestamp representing the date of the call
...
...
@@ -110,17 +110,17 @@ class HistoryItem {
std
::
string
account_id_
;
/**
* Wether or not a recording exist for this call
* W
h
ether or not a recording exist for this call
*/
std
::
string
recording_file_
;
/**
* The conference ID for this call (if any)
*/
* The conference ID for this call (if any)
*/
std
::
string
confID_
;
/**
* Time added to conference
* Time added to conference
*/
std
::
string
timeAdded_
;
};
...
...
daemon/src/history/historymanager.cpp
View file @
67051db1
...
...
@@ -35,30 +35,10 @@
#include
<cc++/file.h>
#include
<time.h>
namespace
{
static
void
free_history
(
HistoryItemMap
&
history_items
)
{
HistoryItemMap
::
iterator
iter
;
for
(
iter
=
history_items
.
begin
();
iter
!=
history_items
.
end
();
++
iter
)
delete
*
iter
;
history_items
.
clear
();
}
}
// end anonymous namespace
HistoryManager
::
HistoryManager
()
:
history_loaded_
(
false
),
history_path_
(
""
)
{
}
HistoryManager
::~
HistoryManager
()
{
free_history
(
history_items_
);
}
HistoryManager
::
HistoryManager
()
:
history_loaded_
(
false
),
history_path_
(
""
)
{}
int
HistoryManager
::
load_history
(
int
limit
,
std
::
string
path
)
int
HistoryManager
::
load_history
(
int
limit
,
const
std
::
string
&
path
)
{
Conf
::
ConfigTree
history_list
;
create_history_path
(
path
);
...
...
@@ -97,19 +77,19 @@ int HistoryManager::load_history_items_map(Conf::ConfigTree *history_list, int l
int
nb_items
=
0
;
for
(
Conf
::
TokenList
::
iterator
iter
=
sections
.
begin
();
iter
!=
sections
.
end
();
++
iter
)
{
CallType
type
=
(
CallType
)
getConfigInt
(
*
iter
,
"type"
,
history_list
);
string
timestamp_start
=
getConfigString
(
*
iter
,
"timestamp_start"
,
history_list
);
string
timestamp_stop
=
getConfigString
(
*
iter
,
"timestamp_stop"
,
history_list
);
string
name
=
getConfigString
(
*
iter
,
"name"
,
history_list
);
string
number
=
getConfigString
(
*
iter
,
"number"
,
history_list
);
string
callID
=
getConfigString
(
*
iter
,
"id"
,
history_list
);
string
accountID
=
getConfigString
(
*
iter
,
"accountid"
,
history_list
);
string
recording_file
=
getConfigString
(
*
iter
,
"recordfile"
,
history_list
);
string
confID
=
getConfigString
(
*
iter
,
"confid"
,
history_list
);
string
time
_a
dded
=
getConfigString
(
*
iter
,
"timeadded"
,
history_list
);
string
timestamp_start
(
getConfigString
(
*
iter
,
"timestamp_start"
,
history_list
)
)
;
string
timestamp_stop
(
getConfigString
(
*
iter
,
"timestamp_stop"
,
history_list
)
)
;
string
name
(
getConfigString
(
*
iter
,
"name"
,
history_list
)
)
;
string
number
(
getConfigString
(
*
iter
,
"number"
,
history_list
)
)
;
string
callID
(
getConfigString
(
*
iter
,
"id"
,
history_list
)
)
;
string
accountID
(
getConfigString
(
*
iter
,
"accountid"
,
history_list
)
)
;
string
recording_file
(
getConfigString
(
*
iter
,
"recordfile"
,
history_list
)
)
;
string
confID
(
getConfigString
(
*
iter
,
"confid"
,
history_list
)
)
;
string
time
A
dded
(
getConfigString
(
*
iter
,
"timeadded"
,
history_list
)
)
;
// Make a check on the start timestamp to know it is loadable according to CONFIG_HISTORY_LIMIT
if
(
atoi
(
timestamp_start
.
c_str
())
>=
((
int
)
current_timestamp
-
history_limit
))
{
HistoryItem
*
item
=
new
HistoryI
tem
(
timestamp_start
,
type
,
timestamp_stop
,
name
,
number
,
callID
,
accountID
,
recording_file
,
confID
,
time
_a
dded
);
HistoryItem
i
tem
(
timestamp_start
,
type
,
timestamp_stop
,
name
,
number
,
callID
,
accountID
,
recording_file
,
confID
,
time
A
dded
);
add_new_history_entry
(
item
);
++
nb_items
;
}
...
...
@@ -128,10 +108,8 @@ bool HistoryManager::save_history_to_file(Conf::ConfigTree *history_list)
int
HistoryManager
::
save_history_items_map
(
Conf
::
ConfigTree
*
history_list
)
{
int
items_saved
=
0
;
for
(
HistoryItemMap
::
iterator
iter
=
history_items_
.
begin
();
iter
!=
history_items_
.
end
();
++
iter
)
{
HistoryItem
*
item
=
*
iter
;
if
(
item
and
item
->
save
(
&
history_list
))
for
(
std
::
vector
<
HistoryItem
>::
iterator
iter
=
history_items_
.
begin
();
iter
!=
history_items_
.
end
();
++
iter
)
{
if
(
iter
->
save
(
&
history_list
))
++
items_saved
;
else
DEBUG
(
"can't save NULL history item
\n
"
);
...
...
@@ -140,7 +118,7 @@ int HistoryManager::save_history_items_map(Conf::ConfigTree *history_list)
return
items_saved
;
}
void
HistoryManager
::
add_new_history_entry
(
HistoryItem
*
new_item
)
void
HistoryManager
::
add_new_history_entry
(
const
HistoryItem
&
new_item
)
{
// Add it in the map
history_items_
.
push_back
(
new_item
);
...
...
@@ -148,7 +126,6 @@ void HistoryManager::add_new_history_entry(HistoryItem *new_item)
int
HistoryManager
::
create_history_path
(
std
::
string
path
)
{
std
::
string
userdata
,
xdg_env
,
xdg_data
;
xdg_data
=
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
+
".local/share/sflphone"
;
...
...
@@ -158,8 +135,7 @@ int HistoryManager::create_history_path(std::string path)
// Else we 'll the standard one, ie: XDG_DATA_HOME = $HOMEDIR/.local/share/sflphone
if
(
XDG_DATA_HOME
!=
NULL
)
{
xdg_env
=
std
::
string
(
XDG_DATA_HOME
);
(
xdg_env
.
length
()
>
0
)
?
userdata
=
xdg_env
:
userdata
=
xdg_data
;
(
xdg_env
.
length
()
>
0
)
?
userdata
=
xdg_env
:
userdata
=
xdg_data
;
}
else
userdata
=
xdg_data
;
...
...
@@ -186,7 +162,7 @@ HistoryManager::getConfigInt(const std::string& section, const std::string& name
try
{
return
history_list
->
getConfigTreeItemIntValue
(
section
,
name
);
}
catch
(
const
Conf
::
ConfigTreeItemException
&
e
)
{
throw
e
;
throw
;
}
return
0
;
...
...
@@ -198,39 +174,30 @@ HistoryManager::getConfigString(const std::string& section, const std::string& n
try
{
return
history_list
->
getConfigTreeItemValue
(
section
,
name
);
}
catch
(
const
Conf
::
ConfigTreeItemException
&
e
)
{
throw
e
;
throw
;
}
return
""
;
}
std
::
vector
<
std
::
string
>
HistoryManager
::
get_history_serialized
()
std
::
vector
<
std
::
string
>
HistoryManager
::
get_history_serialized
()
const
{
std
::
vector
<
std
::
string
>
serialized
;
HistoryItemMap
::
iterator
iter
;
DEBUG
(
"HistoryManager: Get history serialized"
);
for
(
iter
=
history_items_
.
begin
();
iter
!=
history_items_
.
end
();
++
iter
)
{
HistoryItem
*
current
=
*
iter
;
if
(
current
)
serialized
.
push_back
(
current
->
serialize
());
}
for
(
std
::
vector
<
HistoryItem
>::
const_iterator
iter
=
history_items_
.
begin
();
iter
!=
history_items_
.
end
();
++
iter
)
serialized
.
push_back
(
iter
->
serialize
());
return
serialized
;
}
int
HistoryManager
::
set_serialized_history
(
std
::
vector
<
std
::
string
>
history
,
int
limit
)
int
HistoryManager
::
set_serialized_history
(
const
std
::
vector
<
std
::
string
>
&
history
,
int
limit
)
{
int
history_limit
;
time_t
current_timestamp
;
DEBUG
(
"HistoryManager: Set serialized history"
);
// Clear the existing history
free_history
(
history_items_
);
history_items_
.
clear
();
// We want to save only the items recent enough (ie compared to CONFIG_HISTORY_LIMIT)
// Get the current timestamp
...
...
@@ -238,15 +205,14 @@ int HistoryManager::set_serialized_history(std::vector<std::string> history, int
history_limit
=
get_unix_timestamp_equivalent
(
limit
);
int
items_added
=
0
;
for
(
std
::
vector
<
std
::
string
>::
iterator
iter
=
history
.
begin
()
;
iter
!=
history
.
end
()
;
++
iter
)
{
HistoryItem
*
new_item
=
new
HistoryItem
(
*
iter
);
int
item_timestamp
=
atoi
(
new_item
->
get_timestamp
().
c_str
());
for
(
std
::
vector
<
std
::
string
>::
const_
iterator
iter
=
history
.
begin
()
;
iter
!=
history
.
end
()
;
++
iter
)
{
HistoryItem
new_item
(
*
iter
);
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
;
}
}
return
items_added
;
...
...
daemon/src/history/historymanager.h
View file @
67051db1
...
...
@@ -38,8 +38,6 @@
#define DAY_UNIX_TIMESTAMP 86400 // Number of seconds in one day: 60 x 60 x 24
typedef
std
::
vector
<
HistoryItem
*>
HistoryItemMap
;
class
HistoryManager
{
public:
...
...
@@ -48,17 +46,12 @@ class HistoryManager {
*/
HistoryManager
();
/*
* Destructor
*/
~
HistoryManager
();
/**
*@param path A specific file to use; if empty, use the global one
*
*@return int The number of history items successfully loaded
*/
int
load_history
(
int
limit
,
std
::
string
path
=
""
);
int
load_history
(
int
limit
,
const
std
::
string
&
path
=
""
);
/**
*@return bool True if the history has been successfully saved in the file
...
...
@@ -103,9 +96,9 @@ class HistoryManager {
return
history_items_
.
size
();
}
std
::
vector
<
std
::
string
>
get_history_serialized
();
std
::
vector
<
std
::
string
>
get_history_serialized
()
const
;
int
set_serialized_history
(
std
::
vector
<
std
::
string
>
history
,
int
limit
);
int
set_serialized_history
(
const
std
::
vector
<
std
::
string
>
&
history
,
int
limit
);
private:
int
get_unix_timestamp_equivalent
(
int
days
)
const
{
...
...
@@ -124,12 +117,12 @@ class HistoryManager {
/*
* Add a new history item in the data structure
*/
void
add_new_history_entry
(
HistoryItem
*
new_item
);
void
add_new_history_entry
(
const
HistoryItem
&
new_item
);
/*
* Map containing the history items
*/
HistoryItem
Map
history_items_
;
std
::
vector
<
HistoryItem
>
history_items_
;
/*
* History has been loaded
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment