Update of /cvsroot/playerstage/code/player/client_libs/libplayerc++
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8365/client_libs/libplayerc++
Modified Files:
Makefile.am playerc++.h
Added Files:
healthproxy.cc
Log Message:
Added health proxy for monitoring system statistics
--- NEW FILE: healthproxy.cc ---
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2000-2003
* Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* Author: Radu Bogdan Rusu
* client-side Health device
*/
#include "playerc++.h"
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
using namespace PlayerCc;
HealthProxy::HealthProxy(PlayerClient *aPc, uint aIndex)
: ClientProxy(aPc, aIndex),
mDevice(NULL)
{
Subscribe(aIndex);
// how can I get this into the clientproxy.cc?
// right now, we're dependent on knowing its device type
mInfo = &(mDevice->info);
}
HealthProxy::~HealthProxy()
{
Unsubscribe();
}
void
HealthProxy::Subscribe(uint aIndex)
{
scoped_lock_t lock(mPc->mMutex);
mDevice = playerc_health_create(mClient, aIndex);
if (NULL==mDevice)
throw PlayerError("HealthProxy::HealthProxy()", "could not create");
if (0 != playerc_health_subscribe(mDevice, PLAYER_OPEN_MODE))
throw PlayerError("HealthProxy::HealthProxy()", "could not subscribe");
}
void
HealthProxy::Unsubscribe()
{
assert(NULL!=mDevice);
scoped_lock_t lock(mPc->mMutex);
playerc_health_unsubscribe(mDevice);
playerc_health_destroy(mDevice);
mDevice = NULL;
}
float HealthProxy::GetIdleCPU() {
return mDevice->cpu_usage.idle;
}
float HealthProxy::GetSystemCPU() {
return mDevice->cpu_usage.system;
}
float HealthProxy::GetUserCPU() {
return mDevice->cpu_usage.user;
}
int64_t HealthProxy::GetMemTotal() {
return mDevice->mem.total;
}
int64_t HealthProxy::GetMemUsed() {
return mDevice->mem.used;
}
int64_t HealthProxy::GetMemFree() {
return mDevice->mem.free;
}
int64_t HealthProxy::GetSwapTotal() {
return mDevice->swap.total;
}
int64_t HealthProxy::GetSwapUsed() {
return mDevice->swap.used;
}
int64_t HealthProxy::GetSwapFree() {
return mDevice->swap.free;
}
float HealthProxy::GetPercMemUsed() {
return (100.00 * (float)GetMemUsed()/GetMemTotal());
}
float HealthProxy::GetPercSwapUsed() {
return (100.00 * (float)(GetSwapUsed())/GetSwapTotal());
}
float HealthProxy::GetPercTotalUsed() {
return (100.00 *
(float)(GetMemUsed()+GetSwapUsed())/(GetMemTotal()+GetSwapTotal()));
}
Index: playerc++.h
===================================================================
RCS file:
/cvsroot/playerstage/code/player/client_libs/libplayerc++/playerc++.h,v
retrieving revision 1.69
retrieving revision 1.70
diff -C2 -d -r1.69 -r1.70
*** playerc++.h 2 Aug 2006 17:24:51 -0000 1.69
--- playerc++.h 7 Aug 2006 14:17:59 -0000 1.70
***************
*** 886,889 ****
--- 886,945 ----
};
+ /**
+ The @p HealthProxy class is used to get infos of the player-server. */
+ class HealthProxy : public ClientProxy
+ {
+
+ private:
+
+ void Subscribe(uint aIndex);
+ void Unsubscribe();
+
+ // libplayerc data structure
+ playerc_health_t *mDevice;
+
+ public:
+ /// constructor
+ HealthProxy(PlayerClient *aPc, uint aIndex=0);
+ /// destructor
+ ~HealthProxy();
+
+ /// Get idle CPU load in percents
+ float GetIdleCPU();
+
+ /// Get system CPU load in percents
+ float GetSystemCPU();
+
+ /// Get user CPU load in percents
+ float GetUserCPU();
+
+ /// Get total amount of memory
+ int64_t GetMemTotal();
+
+ /// Get amount of memory used
+ int64_t GetMemUsed();
+
+ /// Get amount of free memory
+ int64_t GetMemFree();
+
+ /// Get total amount of swap
+ int64_t GetSwapTotal();
+
+ /// Get amount of swap used
+ int64_t GetSwapUsed();
+
+ /// Get amount of free swap space
+ int64_t GetSwapFree();
+
+ /// Get percentage of used RAM
+ float GetPercMemUsed();
+
+ /// Get percentage of used SWAP
+ float GetPercSwapUsed();
+
+ /// Get percentage of totally used memory (swap and ram)
+ float GetPercTotalUsed();
+ };
+
Index: Makefile.am
===================================================================
RCS file:
/cvsroot/playerstage/code/player/client_libs/libplayerc++/Makefile.am,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** Makefile.am 2 Aug 2006 17:24:51 -0000 1.41
--- Makefile.am 7 Aug 2006 14:17:59 -0000 1.42
***************
*** 41,44 ****
--- 41,45 ----
graphics3dproxy.cc \
gripperproxy.cc \
+ healthproxy.cc \
irproxy.cc \
laserproxy.cc \
***************
*** 60,64 ****
speechrecognitionproxy.cc \
wifiproxy.cc \
! wsnproxy.cc
# not in libplayerc yet \
--- 61,65 ----
speechrecognitionproxy.cc \
wifiproxy.cc \
! wsnproxy.cc
# not in libplayerc yet \
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit