cleaner API and better doxygen comment
This commit is contained in:
@@ -52,7 +52,7 @@ install: $(LIBNAME)
|
|||||||
ldconfig
|
ldconfig
|
||||||
|
|
||||||
install_dev: install
|
install_dev: install
|
||||||
@ln -s $(DESTDIR)$(libdir)/$(LIBNAME) $(DESTDIR)$(libdir)/$(LIBRARY)
|
@ln -f -s $(DESTDIR)$(libdir)/$(LIBNAME) $(DESTDIR)$(libdir)/$(LIBRARY)
|
||||||
install -m 755 libnethogs.a $(DESTDIR)$(libdir)
|
install -m 755 libnethogs.a $(DESTDIR)$(libdir)
|
||||||
@echo "Installed libnethogs.a to $(DESTDIR)$(libdir)"
|
@echo "Installed libnethogs.a to $(DESTDIR)$(libdir)"
|
||||||
install -d -m 755 $(DESTDIR)$(incdir)
|
install -d -m 755 $(DESTDIR)$(incdir)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ 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<uint64_t, NethogsMonitorUpdate> NethogsAppUpdateMap;
|
typedef std::map<void*, NethogsMonitorUpdate> NethogsAppUpdateMap;
|
||||||
static NethogsAppUpdateMap monitor_update_data;
|
static NethogsAppUpdateMap monitor_update_data;
|
||||||
|
|
||||||
static int monitor_refresh_delay = 1;
|
static int monitor_refresh_delay = 1;
|
||||||
@@ -51,11 +51,6 @@ static std::pair<int, int> create_self_pipe()
|
|||||||
return std::make_pair(pfd[0], pfd[1]);
|
return std::make_pair(pfd[0], pfd[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t getProcAsKey(ProcList * curproc)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<uint64_t>(curproc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool wait_for_next_trigger()
|
static bool wait_for_next_trigger()
|
||||||
{
|
{
|
||||||
if( pc_loop_use_select )
|
if( pc_loop_use_select )
|
||||||
@@ -211,13 +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(getProcAsKey(curproc));
|
NethogsAppUpdateMap::iterator it = monitor_update_data.find(curproc);
|
||||||
if( it != monitor_update_data.end() )
|
if( it != monitor_update_data.end() )
|
||||||
{
|
{
|
||||||
NethogsMonitorUpdate& data = it->second;
|
NethogsMonitorUpdate& data = it->second;
|
||||||
data.action = NETHOGS_APP_ACTION_REMOVE;
|
(*cb)(NETHOGS_APP_ACTION_REMOVE, &data);
|
||||||
(*cb)(&data);
|
monitor_update_data.erase(curproc);
|
||||||
monitor_update_data.erase(getProcAsKey(curproc));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcList * todelete = curproc;
|
ProcList * todelete = curproc;
|
||||||
@@ -247,8 +241,8 @@ 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(getProcAsKey(curproc)) == monitor_update_data.end());
|
bool const new_data = (monitor_update_data.find(curproc) == monitor_update_data.end());
|
||||||
NethogsMonitorUpdate &data = monitor_update_data[getProcAsKey(curproc)];
|
NethogsMonitorUpdate &data = monitor_update_data[curproc];
|
||||||
|
|
||||||
bool data_change = false;
|
bool data_change = false;
|
||||||
if( new_data )
|
if( new_data )
|
||||||
@@ -273,8 +267,7 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
|
|
||||||
if( data_change )
|
if( data_change )
|
||||||
{
|
{
|
||||||
data.action = NETHOGS_APP_ACTION_SET;
|
(*cb)(NETHOGS_APP_ACTION_SET, &data);
|
||||||
(*cb)(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//next
|
//next
|
||||||
|
|||||||
18
libnethogs.h
18
libnethogs.h
@@ -20,8 +20,6 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct NethogsMonitorUpdate
|
typedef struct NethogsMonitorUpdate
|
||||||
{
|
{
|
||||||
int action; // NETHOGS_APP_ACTION_SET or NETHOGS_APP_ACTION_REMOVE
|
|
||||||
uint64_t key; //A unique key for the record, used with set/remove actions
|
|
||||||
const char* name;
|
const char* name;
|
||||||
int pid;
|
int pid;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
@@ -32,12 +30,22 @@ typedef struct NethogsMonitorUpdate
|
|||||||
float recv_kbs;
|
float recv_kbs;
|
||||||
} NethogsMonitorUpdate;
|
} NethogsMonitorUpdate;
|
||||||
|
|
||||||
typedef void(*NethogsMonitorCallback)(NethogsMonitorUpdate const*);
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
* @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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enter the process monitoring loop and reports updates using the
|
* @brief Enter the process monitoring loop and reports updates using the
|
||||||
* callback provided as parameter.
|
* callback provided as parameter.
|
||||||
* This call will block until nethogsmonitor_breakloop is called or a failure occurs.
|
* This call will block until nethogsmonitor_breakloop() is called or a failure occurs.
|
||||||
* @param cb A pointer to a callback function following the NethogsMonitorCallback definition
|
* @param cb A pointer to a callback function following the NethogsMonitorCallback definition
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user