added a record_id member to the update struct
This commit is contained in:
@@ -23,8 +23,8 @@ extern Process * unknownip;
|
|||||||
static std::pair<int,int> self_pipe = std::make_pair(-1, -1);
|
static std::pair<int,int> self_pipe = std::make_pair(-1, -1);
|
||||||
|
|
||||||
static bool monitor_run_flag = false;
|
static bool monitor_run_flag = false;
|
||||||
typedef std::map<void*, NethogsMonitorUpdate> NethogsAppUpdateMap;
|
typedef std::map<void*, NethogsMonitorRecord> NethogsRecordMap;
|
||||||
static NethogsAppUpdateMap monitor_update_data;
|
static NethogsRecordMap monitor_record_map;
|
||||||
|
|
||||||
static int monitor_refresh_delay = 1;
|
static int monitor_refresh_delay = 1;
|
||||||
static time_t monitor_last_refresh_time = 0;
|
static time_t monitor_last_refresh_time = 0;
|
||||||
@@ -206,12 +206,12 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
std::cout << "PROC: Deleting process\n";
|
std::cout << "PROC: Deleting process\n";
|
||||||
|
|
||||||
NethogsAppUpdateMap::iterator it = monitor_update_data.find(curproc);
|
NethogsRecordMap::iterator it = monitor_record_map.find(curproc);
|
||||||
if( it != monitor_update_data.end() )
|
if( it != monitor_record_map.end() )
|
||||||
{
|
{
|
||||||
NethogsMonitorUpdate& data = it->second;
|
NethogsMonitorRecord& data = it->second;
|
||||||
(*cb)(NETHOGS_APP_ACTION_REMOVE, &data);
|
(*cb)(NETHOGS_APP_ACTION_REMOVE, &data);
|
||||||
monitor_update_data.erase(curproc);
|
monitor_record_map.erase(curproc);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcList * todelete = curproc;
|
ProcList * todelete = curproc;
|
||||||
@@ -241,14 +241,17 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
curproc->getVal()->gettotal (&recv_bytes, &sent_bytes);
|
curproc->getVal()->gettotal (&recv_bytes, &sent_bytes);
|
||||||
|
|
||||||
//notify update
|
//notify update
|
||||||
bool const new_data = (monitor_update_data.find(curproc) == monitor_update_data.end());
|
bool const new_data = (monitor_record_map.find(curproc) == monitor_record_map.end());
|
||||||
NethogsMonitorUpdate &data = monitor_update_data[curproc];
|
NethogsMonitorRecord &data = monitor_record_map[curproc];
|
||||||
|
|
||||||
bool data_change = false;
|
bool data_change = false;
|
||||||
if( new_data )
|
if( new_data )
|
||||||
{
|
{
|
||||||
data_change = true;
|
data_change = true;
|
||||||
|
static int record_id = 0;
|
||||||
|
++record_id;
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
|
data.record_id = record_id;
|
||||||
data.name = curproc->getVal()->name;
|
data.name = curproc->getVal()->name;
|
||||||
data.pid = curproc->getVal()->pid;
|
data.pid = curproc->getVal()->pid;
|
||||||
}
|
}
|
||||||
|
|||||||
11
libnethogs.h
11
libnethogs.h
@@ -18,8 +18,9 @@ extern "C" {
|
|||||||
#define NETHOGS_STATUS_FAILURE 1 //generic error
|
#define NETHOGS_STATUS_FAILURE 1 //generic error
|
||||||
#define NETHOGS_STATUS_NO_DEVICE 2 //no device foundr
|
#define NETHOGS_STATUS_NO_DEVICE 2 //no device foundr
|
||||||
|
|
||||||
typedef struct NethogsMonitorUpdate
|
typedef struct NethogsMonitorRecord
|
||||||
{
|
{
|
||||||
|
int record_id;
|
||||||
const char* name;
|
const char* name;
|
||||||
int pid;
|
int pid;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
@@ -28,19 +29,19 @@ typedef struct NethogsMonitorUpdate
|
|||||||
uint32_t recv_bytes;
|
uint32_t recv_bytes;
|
||||||
float sent_kbs;
|
float sent_kbs;
|
||||||
float recv_kbs;
|
float recv_kbs;
|
||||||
} NethogsMonitorUpdate;
|
} NethogsMonitorRecord;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Defines a callback to handle updates about applications
|
* @brief Defines a callback to handle updates about applications
|
||||||
* @param action NETHOGS_APP_ACTION_SET if data is beeing added or updated,
|
* @param action NETHOGS_APP_ACTION_SET if data is beeing added or updated,
|
||||||
* NETHOGS_APP_ACTION_REMOVE if data is beeing removed.
|
* NETHOGS_APP_ACTION_REMOVE if data is beeing removed.
|
||||||
* the 'data' pointer is used to uniquely identify the data beeing update or removed.
|
* the record_id member is used to uniquely identify the data beeing update or removed.
|
||||||
* @param data a pointer to an application usage data. the pointer remains valid until
|
* @param data a pointer to an application usage data. the pointer remains valid until
|
||||||
* the callback is called with NETHOGS_APP_ACTION_REMOVE for the same pointer.
|
* the callback is called with NETHOGS_APP_ACTION_REMOVE for the same pointer.
|
||||||
* the user should not modify the content of the structure pointed by data.
|
* the user should not modify the content of the structure pointed by data.
|
||||||
*/
|
*/
|
||||||
typedef void(*NethogsMonitorCallback)(int action, NethogsMonitorUpdate const* data);
|
typedef void(*NethogsMonitorCallback)(int action, NethogsMonitorRecord const* data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enter the process monitoring loop and reports updates using the
|
* @brief Enter the process monitoring loop and reports updates using the
|
||||||
|
|||||||
Reference in New Issue
Block a user