diff --git a/libnethogs.cpp b/libnethogs.cpp index 1f43164..4fd826e 100644 --- a/libnethogs.cpp +++ b/libnethogs.cpp @@ -23,8 +23,8 @@ extern Process * unknownip; static std::pair self_pipe = std::make_pair(-1, -1); static bool monitor_run_flag = false; -typedef std::map NethogsAppUpdateMap; -static NethogsAppUpdateMap monitor_update_data; +typedef std::map NethogsRecordMap; +static NethogsRecordMap monitor_record_map; static int monitor_refresh_delay = 1; static time_t monitor_last_refresh_time = 0; @@ -206,12 +206,12 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb) if (DEBUG) std::cout << "PROC: Deleting process\n"; - NethogsAppUpdateMap::iterator it = monitor_update_data.find(curproc); - if( it != monitor_update_data.end() ) + NethogsRecordMap::iterator it = monitor_record_map.find(curproc); + if( it != monitor_record_map.end() ) { - NethogsMonitorUpdate& data = it->second; + NethogsMonitorRecord& data = it->second; (*cb)(NETHOGS_APP_ACTION_REMOVE, &data); - monitor_update_data.erase(curproc); + monitor_record_map.erase(curproc); } ProcList * todelete = curproc; @@ -241,14 +241,17 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb) curproc->getVal()->gettotal (&recv_bytes, &sent_bytes); //notify update - bool const new_data = (monitor_update_data.find(curproc) == monitor_update_data.end()); - NethogsMonitorUpdate &data = monitor_update_data[curproc]; + bool const new_data = (monitor_record_map.find(curproc) == monitor_record_map.end()); + NethogsMonitorRecord &data = monitor_record_map[curproc]; bool data_change = false; if( new_data ) { data_change = true; + static int record_id = 0; + ++record_id; memset(&data, 0, sizeof(data)); + data.record_id = record_id; data.name = curproc->getVal()->name; data.pid = curproc->getVal()->pid; } diff --git a/libnethogs.h b/libnethogs.h index 269a567..afde2a4 100644 --- a/libnethogs.h +++ b/libnethogs.h @@ -18,8 +18,9 @@ extern "C" { #define NETHOGS_STATUS_FAILURE 1 //generic error #define NETHOGS_STATUS_NO_DEVICE 2 //no device foundr -typedef struct NethogsMonitorUpdate -{ +typedef struct NethogsMonitorRecord +{ + int record_id; const char* name; int pid; uint32_t uid; @@ -28,19 +29,19 @@ typedef struct NethogsMonitorUpdate uint32_t recv_bytes; float sent_kbs; float recv_kbs; -} NethogsMonitorUpdate; +} NethogsMonitorRecord; /** * @brief Defines a callback to handle updates about applications * @param action NETHOGS_APP_ACTION_SET if data is beeing added or updated, * 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 * 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. */ -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