Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1316 → Rev 1317

/kernel/trunk/test/sysinfo/test.c
0,0 → 1,55
/*
* Copyright (C) 2005 Jakub Vana
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <print.h>
#include <debug.h>
#include <panic.h>
 
#include <test.h>
#include <sysinfo/sysinfo.h>
/*
static __native counter(sysinfo_item_t *root)
{
static __native i=0;
return i++;
}*/
 
void test(void)
{
/* sysinfo_set_item_val("Ahoj.lidi.uaaaa",NULL,9);
sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,15);
sysinfo_set_item_val("Ahoj.lidi",NULL,64);
sysinfo_set_item_function("Ahoj",NULL,counter);
sysinfo_dump(NULL,0);
sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,75);
sysinfo_dump(NULL,0);
sysinfo_dump(NULL,0);
sysinfo_dump(NULL,0);*/
sysinfo_dump(NULL,0);
}
/kernel/trunk/kernel.config
134,6 → 134,7
@ "mm/slab1" SLAB test1 - No CPU-cache
@ "mm/slab2" SLAB test2 - SMP CPU cache
@ "fault/fault1" Write to NULL (maybe page fault)
@ "sysinfo" Sysinfo fill and dump test
@ [ARCH=ia64] "mm/purge1" Itanium TLB purge test
@ [ARCH=mips32] "debug/mips1" Mips breakpoint-debug test
! CONFIG_TEST (choice)
/kernel/trunk/genarch/src/fb/fb.c
30,6 → 30,7
#include <genarch/fb/fb.h>
#include <console/chardev.h>
#include <console/console.h>
#include <sysinfo/sysinfo.h>
#include <mm/slab.h>
#include <panic.h>
#include <memstr.h>
358,4 → 359,14
 
chardev_initialize("fb", &framebuffer, &fb_ops);
stdout = &framebuffer;
sysinfo_set_item_val("Framebuffer",NULL,true);
sysinfo_set_item_val("Framebuffer.width",NULL,x);
sysinfo_set_item_val("Framebuffer.height",NULL,y);
sysinfo_set_item_val("Framebuffer.scanline",NULL,scan);
sysinfo_set_item_val("Framebuffer.bpp",NULL,bpp);
sysinfo_set_item_val("Framebuffer.address",NULL,addr);
 
 
}
/kernel/trunk/generic/include/sysinfo/sysinfo.h
0,0 → 1,53
#include <arch/types.h>
 
typedef union sysinfo_item_val
{
__native val;
void *fn;
}sysinfo_item_val_t;
 
typedef struct sysinfo_item
{
char *name;
union
{
__native val;
void *fn;
}val;
 
union
{
struct sysinfo_item *table;
void *fn;
}subinfo;
 
struct sysinfo_item *next;
int val_type;
int subinfo_type;
}sysinfo_item_t;
 
#define SYSINFO_VAL_VAL 0
#define SYSINFO_VAL_FUNCTION 1
#define SYSINFO_VAL_UNDEFINED '?'
 
#define SYSINFO_SUBINFO_NONE 0
#define SYSINFO_SUBINFO_TABLE 1
#define SYSINFO_SUBINFO_FUNCTION 2
 
 
typedef __native (*sysinfo_val_fn_t)(sysinfo_item_t *root);
typedef __native (*sysinfo_subinfo_fn_t)(const char *subname);
 
typedef struct sysinfo_rettype
{
__native val;
__native valid;
}sysinfo_rettype_t;
 
void sysinfo_set_item_val(const char *name,sysinfo_item_t **root,__native val);
void sysinfo_dump(sysinfo_item_t **root,int depth);
void sysinfo_set_item_function(const char *name,sysinfo_item_t **root,sysinfo_val_fn_t fn);
void sysinfo_set_item_undefined(const char *name,sysinfo_item_t **root);
 
sysinfo_rettype_t sysinfo_get_val(const char *name,sysinfo_item_t **root);
 
/kernel/trunk/generic/src/sysinfo/sysinfo.c
0,0 → 1,222
#include <sysinfo/sysinfo.h>
#include <mm/slab.h>
#include <print.h>
 
sysinfo_item_t *_root=NULL;
 
 
static sysinfo_item_t* sysinfo_find_item(const char *name,sysinfo_item_t *subtree)
{
if(subtree==NULL) return NULL;
while(subtree!=NULL)
{
int i;
char *a,*b;
a=(char *)name;
b=subtree->name;
while((a[i]==b[i])&&(b[i])) i++;
if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/
if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/
{
if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_find_item(a+i+1,subtree->subinfo.table);
//if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/
return NULL; /*No subinfo*/
}
/* No matches try next*/
subtree=subtree->next;
i=0;
}
return NULL;
}
 
static sysinfo_item_t* sysinfo_create_path(const char *name,sysinfo_item_t **psubtree)
{
sysinfo_item_t *subtree;
subtree = *psubtree;
if(subtree==NULL)
{
sysinfo_item_t *item;
int i=0,j;
item = malloc(sizeof(sysinfo_item_t),0);
ASSERT(item);
*psubtree = item;
item -> next = NULL;
item -> val_type = SYSINFO_VAL_UNDEFINED;
item -> subinfo.table = NULL;
 
while(name[i]&&(name[i]!='.')) i++;
item -> name = malloc(i,0);
ASSERT(item -> name);
 
for(j=0;j<i;j++) item->name[j]=name[j];
item->name[j]=0;
if(name[i]/*=='.'*/)
{
item -> subinfo_type = SYSINFO_SUBINFO_TABLE;
return sysinfo_create_path(name+i+1,&(item->subinfo.table));
}
item -> subinfo_type = SYSINFO_SUBINFO_NONE;
return item;
}
 
while(subtree!=NULL)
{
int i=0,j;
char *a,*b;
a=(char *)name;
b=subtree->name;
while((a[i]==b[i])&&(b[i])) i++;
if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/
if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/
{
if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_create_path(a+i+1,&(subtree->subinfo.table));
if(subtree->subinfo_type==SYSINFO_SUBINFO_NONE)
{
subtree->subinfo_type=SYSINFO_SUBINFO_TABLE;
return sysinfo_create_path(a+i+1,&(subtree->subinfo.table));
}
//if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/
return NULL;
}
/* No matches try next or create new*/
if(subtree->next==NULL)
{
sysinfo_item_t *item;
item = malloc(sizeof(sysinfo_item_t),0);
ASSERT(item);
subtree -> next = item;
item -> next = NULL;
item -> val_type = SYSINFO_VAL_UNDEFINED;
item -> subinfo.table = NULL;
 
i=0;
while(name[i]&&(name[i]!='.')) i++;
 
item -> name = malloc(i,0);
ASSERT(item -> name);
for(j=0;j<i;j++) item->name[j]=name[j];
item->name[j]=0;
 
if(name[i]/*=='.'*/)
{
item -> subinfo_type = SYSINFO_SUBINFO_TABLE;
return sysinfo_create_path(name+i+1,&(item->subinfo.table));
}
item -> subinfo_type = SYSINFO_SUBINFO_NONE;
return item;
 
}
else
{
subtree=subtree->next;
i=0;
}
}
panic("Not reached\n");
return NULL;
}
 
void sysinfo_set_item_val(const char *name,sysinfo_item_t **root,__native val)
{
if(root==NULL) root=&_root;
sysinfo_item_t *item;
item = sysinfo_create_path(name,root); /* If already created create only returns pointer
If ! , create it */
if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */
{
item->val.val=val;
item -> val_type = SYSINFO_VAL_VAL;
}
}
 
void sysinfo_set_item_function(const char *name,sysinfo_item_t **root,sysinfo_val_fn_t fn)
{
if(root==NULL) root=&_root;
sysinfo_item_t *item;
item = sysinfo_create_path(name,root); /* If already created create only returns pointer
If ! , create it */
if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */
{
item->val.fn=fn;
item -> val_type = SYSINFO_VAL_FUNCTION;
}
}
 
 
void sysinfo_set_item_undefined(const char *name,sysinfo_item_t **root)
{
if(root==NULL) root=&_root;
sysinfo_item_t *item;
item = sysinfo_find_item(name,*root);
if(item!=NULL) item -> val_type = SYSINFO_VAL_UNDEFINED;
}
 
 
void sysinfo_dump(sysinfo_item_t **proot,int depth)
{
sysinfo_item_t *root;
if(proot==NULL) proot=&_root;
root = *proot;
while(root!=NULL)
{
 
int i;
__native val=0;
char *vtype=NULL;
for(i=0;i<depth;i++) printf(" ");
switch (root->val_type)
{
case (SYSINFO_VAL_UNDEFINED):
val=0;
vtype="UND";
break;
case (SYSINFO_VAL_VAL):
val=root->val.val;
vtype="VAL";
break;
case (SYSINFO_VAL_FUNCTION):
val=((sysinfo_val_fn_t)(root->val.fn))(root);
vtype="FUN";
break;
}
printf("%s %s val:%d(%X) sub:%s\n",root->name,vtype,val,val,
(root->subinfo_type==SYSINFO_SUBINFO_NONE)?"NON":((root->subinfo_type==SYSINFO_SUBINFO_TABLE)?"TAB":"FUN"));
if(root -> subinfo_type == SYSINFO_SUBINFO_TABLE)
sysinfo_dump(&(root->subinfo.table),depth+1);
root=root->next;
}
}
 
sysinfo_rettype_t sysinfo_get_val(const char *name,sysinfo_item_t **root)
{
/*TODO:
Implement Subsystem subinfo (by function implemented subinfo)
*/
 
sysinfo_rettype_t ret={0,false};
 
if(root==NULL) root=&_root;
sysinfo_item_t *item;
item = sysinfo_find_item(name,*root);
if(item!=NULL)
{
if (item -> val_type == SYSINFO_VAL_UNDEFINED)
return ret;
else ret.valid=true;
if (item -> val_type == SYSINFO_VAL_VAL)
ret.val=item -> val.val;
else ret.val=((sysinfo_val_fn_t)(item->val.fn))(item);
}
return ret;
}
/kernel/trunk/Makefile
163,7 → 163,8
generic/src/ipc/sysipc.c \
generic/src/ipc/ipcrsc.c \
generic/src/ipc/irq.c \
generic/src/security/cap.c
generic/src/security/cap.c \
generic/src/sysinfo/sysinfo.c
 
## Test sources
#