- introduced a SystemInfoHandler class used to watch for stuff when polling isn't needed.
- used it to add a count of running apps (not exactly the same as teams). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25012 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "ActivityMonitor.h"
|
#include "ActivityMonitor.h"
|
||||||
#include "DataSource.h"
|
#include "DataSource.h"
|
||||||
#include "SystemInfo.h"
|
#include "SystemInfo.h"
|
||||||
|
#include "SystemInfoHandler.h"
|
||||||
|
|
||||||
|
|
||||||
struct data_item {
|
struct data_item {
|
||||||
@@ -167,6 +168,7 @@ ActivityView::ActivityView(BMessage* archive)
|
|||||||
ActivityView::~ActivityView()
|
ActivityView::~ActivityView()
|
||||||
{
|
{
|
||||||
delete fOffscreen;
|
delete fOffscreen;
|
||||||
|
delete fSystemInfoHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,6 +184,8 @@ ActivityView::_Init(const BMessage* settings)
|
|||||||
fDrawInterval = kInitialRefreshInterval * 2;
|
fDrawInterval = kInitialRefreshInterval * 2;
|
||||||
fLastRefresh = 0;
|
fLastRefresh = 0;
|
||||||
fDrawResolution = 1;
|
fDrawResolution = 1;
|
||||||
|
|
||||||
|
fSystemInfoHandler = new SystemInfoHandler;
|
||||||
|
|
||||||
if (settings == NULL
|
if (settings == NULL
|
||||||
|| settings->FindBool("show legend", &fShowLegend) != B_OK)
|
|| settings->FindBool("show legend", &fShowLegend) != B_OK)
|
||||||
@@ -349,6 +353,8 @@ ActivityView::RemoveAllDataSources()
|
|||||||
void
|
void
|
||||||
ActivityView::AttachedToWindow()
|
ActivityView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
|
Looper()->AddHandler(fSystemInfoHandler);
|
||||||
|
fSystemInfoHandler->StartWatchingStuff();
|
||||||
BMessage refresh(kMsgRefresh);
|
BMessage refresh(kMsgRefresh);
|
||||||
fRunner = new BMessageRunner(this, &refresh, fRefreshInterval);
|
fRunner = new BMessageRunner(this, &refresh, fRefreshInterval);
|
||||||
|
|
||||||
@@ -359,6 +365,8 @@ ActivityView::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
ActivityView::DetachedFromWindow()
|
ActivityView::DetachedFromWindow()
|
||||||
{
|
{
|
||||||
|
fSystemInfoHandler->StopWatchingStuff();
|
||||||
|
Looper()->RemoveHandler(fSystemInfoHandler);
|
||||||
delete fRunner;
|
delete fRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +746,7 @@ ActivityView::Draw(BRect /*updateRect*/)
|
|||||||
void
|
void
|
||||||
ActivityView::_Refresh()
|
ActivityView::_Refresh()
|
||||||
{
|
{
|
||||||
SystemInfo info;
|
SystemInfo info(fSystemInfoHandler);
|
||||||
|
|
||||||
// TODO: run refresh in another thread to decouple it from the UI!
|
// TODO: run refresh in another thread to decouple it from the UI!
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
class BBitmap;
|
class BBitmap;
|
||||||
class BMessageRunner;
|
class BMessageRunner;
|
||||||
class DataSource;
|
class DataSource;
|
||||||
|
class SystemInfoHandler;
|
||||||
struct data_item;
|
struct data_item;
|
||||||
|
|
||||||
|
|
||||||
@@ -98,6 +99,7 @@ private:
|
|||||||
bigtime_t fDrawInterval;
|
bigtime_t fDrawInterval;
|
||||||
int32 fDrawResolution;
|
int32 fDrawResolution;
|
||||||
bool fShowLegend;
|
bool fShowLegend;
|
||||||
|
SystemInfoHandler* fSystemInfoHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACTIVITY_VIEW_H
|
#endif // ACTIVITY_VIEW_H
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const DataSource* kSources[] = {
|
|||||||
new PortsDataSource(),
|
new PortsDataSource(),
|
||||||
new ThreadsDataSource(),
|
new ThreadsDataSource(),
|
||||||
new TeamsDataSource(),
|
new TeamsDataSource(),
|
||||||
|
new RunningAppsDataSource(),
|
||||||
new CPUUsageDataSource(),
|
new CPUUsageDataSource(),
|
||||||
new CPUCombinedUsageDataSource(),
|
new CPUCombinedUsageDataSource(),
|
||||||
new NetworkUsageDataSource(true),
|
new NetworkUsageDataSource(true),
|
||||||
@@ -530,6 +531,53 @@ TeamsDataSource::AdaptiveScale() const
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
RunningAppsDataSource::RunningAppsDataSource()
|
||||||
|
{
|
||||||
|
SystemInfo info;
|
||||||
|
|
||||||
|
fMinimum = 0;
|
||||||
|
fMaximum = info.MaxRunningApps();
|
||||||
|
|
||||||
|
fColor = (rgb_color){100, 150, 255};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RunningAppsDataSource::~RunningAppsDataSource()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DataSource*
|
||||||
|
RunningAppsDataSource::Copy() const
|
||||||
|
{
|
||||||
|
return new RunningAppsDataSource(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64
|
||||||
|
RunningAppsDataSource::NextValue(SystemInfo& info)
|
||||||
|
{
|
||||||
|
return info.UsedRunningApps();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
RunningAppsDataSource::Label() const
|
||||||
|
{
|
||||||
|
return "Running Applications";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
RunningAppsDataSource::AdaptiveScale() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
CPUUsageDataSource::CPUUsageDataSource(int32 cpu)
|
CPUUsageDataSource::CPUUsageDataSource(int32 cpu)
|
||||||
:
|
:
|
||||||
fPreviousActive(0),
|
fPreviousActive(0),
|
||||||
|
|||||||
@@ -141,6 +141,19 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class RunningAppsDataSource : public DataSource {
|
||||||
|
public:
|
||||||
|
RunningAppsDataSource();
|
||||||
|
virtual ~RunningAppsDataSource();
|
||||||
|
|
||||||
|
virtual DataSource* Copy() const;
|
||||||
|
|
||||||
|
virtual int64 NextValue(SystemInfo& info);
|
||||||
|
virtual const char* Label() const;
|
||||||
|
virtual bool AdaptiveScale() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CPUUsageDataSource : public DataSource {
|
class CPUUsageDataSource : public DataSource {
|
||||||
public:
|
public:
|
||||||
CPUUsageDataSource(int32 cpu = 0);
|
CPUUsageDataSource(int32 cpu = 0);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Application ActivityMonitor :
|
|||||||
ActivityWindow.cpp
|
ActivityWindow.cpp
|
||||||
DataSource.cpp
|
DataSource.cpp
|
||||||
SystemInfo.cpp
|
SystemInfo.cpp
|
||||||
|
SystemInfoHandler.cpp
|
||||||
|
|
||||||
: be tracker $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS)
|
: be tracker $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS)
|
||||||
: ActivityMonitor.rdef
|
: ActivityMonitor.rdef
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "SystemInfo.h"
|
#include "SystemInfo.h"
|
||||||
|
#include "SystemInfoHandler.h"
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -14,12 +15,17 @@
|
|||||||
#include <sys/sockio.h>
|
#include <sys/sockio.h>
|
||||||
|
|
||||||
|
|
||||||
SystemInfo::SystemInfo()
|
SystemInfo::SystemInfo(SystemInfoHandler *handler)
|
||||||
:
|
:
|
||||||
fTime(system_time()),
|
fTime(system_time()),
|
||||||
fRetrievedNetwork(false)
|
fRetrievedNetwork(false),
|
||||||
|
fRunningApps(0)
|
||||||
{
|
{
|
||||||
get_system_info(&fSystemInfo);
|
get_system_info(&fSystemInfo);
|
||||||
|
|
||||||
|
if (handler) {
|
||||||
|
fRunningApps = handler->RunningApps();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +115,20 @@ SystemInfo::MaxTeams() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
SystemInfo::UsedRunningApps() const
|
||||||
|
{
|
||||||
|
return fRunningApps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
SystemInfo::MaxRunningApps() const
|
||||||
|
{
|
||||||
|
return fSystemInfo.max_teams;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SystemInfo::_RetrieveNetwork()
|
SystemInfo::_RetrieveNetwork()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
class SystemInfoHandler;
|
||||||
|
|
||||||
|
|
||||||
class SystemInfo {
|
class SystemInfo {
|
||||||
public:
|
public:
|
||||||
SystemInfo();
|
SystemInfo(SystemInfoHandler *handler=NULL);
|
||||||
~SystemInfo();
|
~SystemInfo();
|
||||||
|
|
||||||
uint64 CachedMemory() const;
|
uint64 CachedMemory() const;
|
||||||
@@ -30,6 +32,9 @@ public:
|
|||||||
uint32 UsedTeams() const;
|
uint32 UsedTeams() const;
|
||||||
uint32 MaxTeams() const;
|
uint32 MaxTeams() const;
|
||||||
|
|
||||||
|
uint32 UsedRunningApps() const;
|
||||||
|
uint32 MaxRunningApps() const;
|
||||||
|
|
||||||
bigtime_t Time() const { return fTime; }
|
bigtime_t Time() const { return fTime; }
|
||||||
uint32 CPUCount() const { return fSystemInfo.cpu_count; }
|
uint32 CPUCount() const { return fSystemInfo.cpu_count; }
|
||||||
const system_info& Info() const { return fSystemInfo; }
|
const system_info& Info() const { return fSystemInfo; }
|
||||||
@@ -45,6 +50,7 @@ private:
|
|||||||
bool fRetrievedNetwork;
|
bool fRetrievedNetwork;
|
||||||
uint64 fBytesReceived;
|
uint64 fBytesReceived;
|
||||||
uint64 fBytesSent;
|
uint64 fBytesSent;
|
||||||
|
uint32 fRunningApps;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYSTEM_INFO_H
|
#endif // SYSTEM_INFO_H
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "SystemInfoHandler.h"
|
||||||
|
|
||||||
|
#include <Handler.h>
|
||||||
|
#include <List.h>
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
SystemInfoHandler::SystemInfoHandler()
|
||||||
|
: BHandler("SystemInfoHandler")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SystemInfoHandler::~SystemInfoHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
SystemInfoHandler::Archive(BMessage *data, bool deep) const
|
||||||
|
{
|
||||||
|
// we don't want ourselves to be archived at all...
|
||||||
|
// return BHandler::Archive(data, deep);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SystemInfoHandler::StartWatchingStuff()
|
||||||
|
{
|
||||||
|
fRunningApps = 0;
|
||||||
|
|
||||||
|
// running applications count
|
||||||
|
BList teamList;
|
||||||
|
be_roster->StartWatching(BMessenger(this),
|
||||||
|
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||||
|
be_roster->GetAppList(&teamList);
|
||||||
|
fRunningApps = teamList.CountItems();
|
||||||
|
teamList.MakeEmpty();
|
||||||
|
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SystemInfoHandler::StopWatchingStuff()
|
||||||
|
{
|
||||||
|
be_roster->StopWatching(BMessenger(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SystemInfoHandler::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case B_SOME_APP_LAUNCHED:
|
||||||
|
fRunningApps++;
|
||||||
|
// XXX: maybe resync periodically in case we miss one
|
||||||
|
break;
|
||||||
|
case B_SOME_APP_QUIT:
|
||||||
|
fRunningApps--;
|
||||||
|
// XXX: maybe resync periodically in case we miss one
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BHandler::MessageReceived(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
SystemInfoHandler::RunningApps() const
|
||||||
|
{
|
||||||
|
return fRunningApps;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef SYSTEM_INFO_HANDLER_H
|
||||||
|
#define SYSTEM_INFO_HANDLER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
#include <Handler.h>
|
||||||
|
|
||||||
|
|
||||||
|
class SystemInfoHandler : public BHandler {
|
||||||
|
public:
|
||||||
|
SystemInfoHandler();
|
||||||
|
//SystemInfoHandler(BMessage *data);
|
||||||
|
virtual ~SystemInfoHandler();
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||||
|
|
||||||
|
void StartWatchingStuff();
|
||||||
|
void StopWatchingStuff();
|
||||||
|
|
||||||
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
|
uint32 RunningApps() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32 fRunningApps;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SYSTEM_INFO_HANDLER_H
|
||||||
Reference in New Issue
Block a user