LCDproc development and user support list

Text archives Help


[Lcdproc] Proposal for a C++ client API


Chronological Thread 
  • From: tian-misc AT c-sait.net (tian-misc AT c-sait.net)
  • Subject: [Lcdproc] Proposal for a C++ client API
  • Date: Thu Jun 17 15:01:01 2004

Hi all,

I discovered LCDproc about one week ago. I found it very interesting even
if I do not have an LCD for the moment (but plan to buy one when I will
have saved some money).

I was suprised that there is no client API. So I began to develop a C++
one. Only a part of what it could be has been done for the moment (the
TODO list is quite long). But I'd just want to know first if you think it
could be useful and possibily integrated in the LCDproc delivery.

Here is what is supported at present :

* Commands (with all options):
* hello
* client_set
* screen_add
* screen_del
* screen_set
* widget_add
* widget_del
* widget_set

* C++ Classes
* LCDClient (for connectivity)
* LCDScreen (reperesenting a screen)
* A class for each widget

* Sensors (Detailled below)
* LCDTimeSensor (send time)
* LCDCpuSensor (CPU load)
* LCDSystemSensor (execute user defined command)

* Widget supporting sensors
* LCDText
* LCDTitle
* LCDHorizontalBar
* LCDVerticalBar

* Automatic ID creation for screens and widgets (optionnal).

* Elements can be created in any order and then attached to their parent.
The command will be sent by the API in the correct order (parent created
before children and options set after creation).



Sensors
---------

A sensor is a C++ object that send some information to a widget. It can
send it when this information change (for example an xmms sensor will wait
for a new track) or at regular intervals.

There is a base class, LCDSensor. A new Sensor has only to inherit from
this one and implement 2 pure virtual methods:
* virtual void waitForChange();
* virtual std::string getCurrentValue();

The first one should only wait for the value to change. The second one
should return what is the current measured value.



Any comments about this are welcome. You can find hereafter a small
example of a complete client. It will display a fixed titlem time on
center of second line and a horizontal bar displaying CPU usage on third
one. As the order doesn't impact anyhting, you should have created all the
widget before the screen and then attach them to it. The command will be
sent to LCDd in correct order.


Best regards,

Tian.

-------------------

#include "LCDHeaders.h"
#include <iostream>

int main(char **argv, int argc)
{
try
{
LCDClient client("localhost", 13666);

LCDScreen screen(&client);
screen.setBackLight(LCD_BACKLIGHT_ON);
screen.setHeartBeat(LCD_HEARTBEAT_OFF);

LCDTitle title("Test");
screen.add(&title);

LCDText text;
screen.add(&text);
text.move(client.getWidth()/2 - 2, 2);

LCDTimeSensor myTime;
myTime.addOnTimeOutWidget(&text, 100);

LCDHorizontalBar bar(&screen);
bar.move(1,3);
bar.setPercentageMax(client.getWidth() * client.getCharWidth());

LCDCpuSensor myCpu;
myCpu.addOnTimeOutWidget(&bar, 10);

for(;;) sleep(10);
}
catch (LCDException e)
{
std::cerr << e.what() << std::endl;
}
}





Archive powered by MHonArc 2.6.18.

Top of page