Changeset 25012

Show
Ignore:
Timestamp:
04/17/08 18:04:18 (7 months ago)
Author:
mmu_man
Message:

- 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).

Location:
haiku/trunk/src/apps/activitymonitor
Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/apps/activitymonitor/ActivityView.cpp

    r25009 r25012  
    2222#include "DataSource.h" 
    2323#include "SystemInfo.h" 
     24#include "SystemInfoHandler.h" 
    2425 
    2526 
     
    168169{ 
    169170        delete fOffscreen; 
     171        delete fSystemInfoHandler; 
    170172} 
    171173 
     
    183185        fLastRefresh = 0; 
    184186        fDrawResolution = 1; 
     187         
     188        fSystemInfoHandler = new SystemInfoHandler; 
    185189 
    186190        if (settings == NULL 
     
    350354ActivityView::AttachedToWindow() 
    351355{ 
     356        Looper()->AddHandler(fSystemInfoHandler); 
     357        fSystemInfoHandler->StartWatchingStuff(); 
    352358        BMessage refresh(kMsgRefresh); 
    353359        fRunner = new BMessageRunner(this, &refresh, fRefreshInterval); 
     
    360366ActivityView::DetachedFromWindow() 
    361367{ 
     368        fSystemInfoHandler->StopWatchingStuff(); 
     369        Looper()->RemoveHandler(fSystemInfoHandler); 
    362370        delete fRunner; 
    363371} 
     
    739747ActivityView::_Refresh() 
    740748{ 
    741         SystemInfo info; 
     749        SystemInfo info(fSystemInfoHandler); 
    742750 
    743751        // TODO: run refresh in another thread to decouple it from the UI! 
  • haiku/trunk/src/apps/activitymonitor/ActivityView.h

    r25009 r25012  
    1515class BMessageRunner; 
    1616class DataSource; 
     17class SystemInfoHandler; 
    1718struct data_item; 
    1819 
     
    99100        int32                           fDrawResolution; 
    100101        bool                            fShowLegend; 
     102        SystemInfoHandler*      fSystemInfoHandler; 
    101103}; 
    102104 
  • haiku/trunk/src/apps/activitymonitor/DataSource.cpp

    r25011 r25012  
    2222        new ThreadsDataSource(), 
    2323        new TeamsDataSource(), 
     24        new RunningAppsDataSource(), 
    2425        new CPUUsageDataSource(), 
    2526        new CPUCombinedUsageDataSource(), 
     
    523524bool 
    524525TeamsDataSource::AdaptiveScale() const 
     526{ 
     527        return true; 
     528} 
     529 
     530 
     531//      #pragma mark - 
     532 
     533 
     534RunningAppsDataSource::RunningAppsDataSource() 
     535{ 
     536        SystemInfo info; 
     537 
     538        fMinimum = 0; 
     539        fMaximum = info.MaxRunningApps(); 
     540 
     541        fColor = (rgb_color){100, 150, 255}; 
     542} 
     543 
     544 
     545RunningAppsDataSource::~RunningAppsDataSource() 
     546{ 
     547} 
     548 
     549 
     550DataSource* 
     551RunningAppsDataSource::Copy() const 
     552{ 
     553        return new RunningAppsDataSource(*this); 
     554} 
     555 
     556 
     557int64 
     558RunningAppsDataSource::NextValue(SystemInfo& info) 
     559{ 
     560        return info.UsedRunningApps(); 
     561} 
     562 
     563 
     564const char* 
     565RunningAppsDataSource::Label() const 
     566{ 
     567        return "Running Applications"; 
     568} 
     569 
     570 
     571bool 
     572RunningAppsDataSource::AdaptiveScale() const 
    525573{ 
    526574        return true; 
  • haiku/trunk/src/apps/activitymonitor/DataSource.h

    r25011 r25012  
    142142 
    143143 
     144class RunningAppsDataSource : public DataSource { 
     145public: 
     146                                                RunningAppsDataSource(); 
     147        virtual                         ~RunningAppsDataSource(); 
     148 
     149        virtual DataSource*     Copy() const; 
     150 
     151        virtual int64           NextValue(SystemInfo& info); 
     152        virtual const char*     Label() const; 
     153        virtual bool            AdaptiveScale() const; 
     154}; 
     155 
     156 
    144157class CPUUsageDataSource : public DataSource { 
    145158public: 
  • haiku/trunk/src/apps/activitymonitor/Jamfile

    r25009 r25012  
    1212        DataSource.cpp 
    1313        SystemInfo.cpp 
     14        SystemInfoHandler.cpp 
    1415 
    1516        : be tracker $(TARGET_LIBSTDC++) $(TARGET_NETWORK_LIBS) 
  • haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp

    r25011 r25012  
    66 
    77#include "SystemInfo.h" 
     8#include "SystemInfoHandler.h" 
    89 
    910#include <net/if.h> 
     
    1516 
    1617 
    17 SystemInfo::SystemInfo() 
     18SystemInfo::SystemInfo(SystemInfoHandler *handler) 
    1819        : 
    1920        fTime(system_time()), 
    20         fRetrievedNetwork(false) 
     21        fRetrievedNetwork(false), 
     22        fRunningApps(0) 
    2123{ 
    2224        get_system_info(&fSystemInfo); 
     25         
     26        if (handler) { 
     27                fRunningApps = handler->RunningApps(); 
     28        } 
    2329} 
    2430 
     
    105111uint32 
    106112SystemInfo::MaxTeams() const 
     113{ 
     114        return fSystemInfo.max_teams; 
     115} 
     116 
     117 
     118uint32 
     119SystemInfo::UsedRunningApps() const 
     120{ 
     121        return fRunningApps; 
     122} 
     123 
     124 
     125uint32 
     126SystemInfo::MaxRunningApps() const 
    107127{ 
    108128        return fSystemInfo.max_teams; 
  • haiku/trunk/src/apps/activitymonitor/SystemInfo.h

    r25011 r25012  
    99#include <OS.h> 
    1010 
     11class SystemInfoHandler; 
     12 
    1113 
    1214class SystemInfo { 
    1315public: 
    14                                                 SystemInfo(); 
     16                                                SystemInfo(SystemInfoHandler *handler=NULL); 
    1517                                                ~SystemInfo(); 
    1618 
     
    3133                        uint32          MaxTeams() const; 
    3234 
     35                        uint32          UsedRunningApps() const; 
     36                        uint32          MaxRunningApps() const; 
     37 
    3338                        bigtime_t       Time() const { return fTime; } 
    3439                        uint32          CPUCount() const { return fSystemInfo.cpu_count; } 
     
    4651        uint64                          fBytesReceived; 
    4752        uint64                          fBytesSent; 
     53        uint32                          fRunningApps; 
    4854}; 
    4955