Appendix A. Memory Plugin Sample Code
This appendix contains the complete code for the sample memory plugin. An explanation of this sample code and how to implement it is provided in A Sample Memory Plugin (in the The Device Management Agent topic) and in Updating the Web UI with the Sample Memory Plugin (in the topic called Using the Web UI Framework to Develop and Customize AP UIs).
This appendix contains the following:
The MemInfoPlugin.c Code
/* forward references declarations */
static void refresh_sysmem (struct dman_refresh_info *info);
static void refresh_detailmem (struct dman_refresh_info *info);
/* setup the sysMem Class */
static void setup_vlrs(void)
struct dman_class* class;
struct dman_property* prop;
class = dman_class_new("sysmem");
dman_class_set_persistence(class, 0);
dman_class_set_type(class, DMAN_CLASS_TYPE_SINGLETON);
prop = dman_property_new ("total");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("used");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("free");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("shared");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("buffers");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("cached");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
/* setup the Detailed Mem Class */
static void setup_detailmem_class(void)
struct dman_class* class;
struct dman_property* prop;
class = dman_class_new("detailmem");
dman_class_set_persistence(class, 0);
dman_class_set_type(class, DMAN_CLASS_TYPE_ANONYMOUS);
prop = dman_property_new ("label");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
prop = dman_property_new ("value");
dman_property_set_writable (prop, 0);
dman_property_set_persistence (prop, 0);
dman_class_add_property (class, prop);
/* setup System Memory Provider */
static void setup_sysmem_provider(void)
struct dman_provider* provider;
provider = dman_provider_new("sysmem");
dman_provider_set_refresh_fn(provider,refresh_sysmem, NULL);
dman_providers_add(provider);
/* setup Detailed Memory Provider */
static void setup_detailmem_provider(void)
struct dman_provider* provider;
provider = dman_provider_new("detailmem");
dman_provider_set_refresh_fn(provider,refresh_detailmem, NULL);
dman_providers_add(provider);
/* System Memory Refresh Function */
static void refresh_sysmem (struct dman_refresh_info *info)
struct dman_instances *instances;
struct dman_class *class;
struct dman_instance *instance = NULL;
if (strcmp(dman_refresh_info_get_class(info), "sysmem") != 0) {
instances = dman_refresh_info_get_instances(info);
dman_instances_delete_class(instances, "sysmem");
/* open file pointer to /proc/memInfo */
fp = fopen("/proc/meminfo", "r");
/*throw away first line of the file*/
fgets(line, sizeof(line),fp);
class = dman_classes_get("sysmem");
/* read information and write into class properties */
fgets(line, sizeof(line), fp);
sscanf(line, "%*s %s %s %s %s %s %s", total, used, free, shared, buffers,
cached);
instance = dman_instance_new(class, NULL);
dman_instance_set_value(instance, "total", total);
dman_instance_set_value(instance, "used", used);
dman_instance_set_value(instance, "free", free);
dman_instance_set_value(instance, "shared", shared);
dman_instance_set_value(instance, "buffers", buffers);
dman_instance_set_value(instance, "cached", cached);
dman_instances_add(instances, instance);
/* Detailed Memory Refresh Function */
static void refresh_detailmem (struct dman_refresh_info *info)
struct dman_instances *instances;
struct dman_class *class;
struct dman_instance *instance = NULL;
if (strcmp(dman_refresh_info_get_class(info), "detailmem") != 0) {
instances = dman_refresh_info_get_instances(info);
dman_instances_delete_class(instances, "detailmem");
/* open file pointer to /proc/memInfo */
fp = fopen("/proc/meminfo", "r");
/*throw away first three lines of the file*/
fgets(line, sizeof(line),fp);
class = dman_classes_get("detailmem");
/* read information and write into class properties */
while (fgets(line, sizeof(line), fp) != NULL) {
sscanf(line, "%s %s %*s", label, value);
instance = dman_instance_new(class, NULL);
dman_instance_set_value(instance, "label", label);
dman_instance_set_value(instance, "value", value);
dman_instances_add(instances, instance);
/* Plug-in Init Function */
void dman_plugin_init(void)
setup_detailmem_provider();
The MemInfoWebUI Code
The meminfo Code (admin-features.hdf)
The Labels_en_us_ds.hdf File
SysMem = System Memory Information
DetailMem = Detailed Memory Information
The Messages_en_us_ds.hdf File
Meminfo = Memory Usage Information
The meminfo-action.hdf File
data = device.sysmem device.detailmem
The meminfo.html Template
<div class="page-header1"><?cs var:localize("Labels.SysMem") ?>:</div>
<table class="sectioned" cellpadding="0" cellspacing="0" width="80%">
<td class="section-header-super"><?cs var:localize("Labels.Total") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Used") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Free") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Shared") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Buffers") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Cached") ?>:</td>
<?cs each:chan = device.sysmem_s ?>
<tr class="<?cs if:row_num % #2 == #0 ?>eventablerow<?cs else ?>oddtablerow<?cs /if
?>">
<td class="section-cell"><?cs var:chan.total ?></td>
<td class="section-cell"><?cs var:chan.used ?></td>
<td class="section-cell"><?cs var:chan.free ?></td>
<td class="section-cell"><?cs var:chan.shared ?></td>
<td class="section-cell"><?cs var:chan.buffers ?></td>
<td class="section-cell"><?cs var:chan.cached ?></td>
<div class="page-header2"><?cs var:localize("Labels.DetailMem") ?>:</div>
<table class="sectioned" cellpadding="0" cellspacing="0" width="80%">
<td class="section-header-super"><?cs var:localize("Labels.Label") ?>:</td>
<td class="section-header-super"><?cs var:localize("Labels.Size") ?>:</td>
<?cs each:chan = device.detailmem_s ?>
<tr class="<?cs if:row_num % #2 == #0 ?>eventablerow<?cs else ?>oddtablerow<?cs /if
?>">
<td class="section-cell"><?cs var:chan.label ?></td>
<td class="section-cell"><?cs var:chan.value ?></td>