who bindings

This commit is contained in:
Doug MacEachern 2005-02-22 01:51:21 +00:00
parent e0063abf7b
commit bd2ef09744
2 changed files with 54 additions and 2 deletions

View File

@ -740,7 +740,28 @@ my %classes = (
plat => 'L'
},
],
Who => [
{
name => 'user', type => 'String',
desc => '',
plat => ''
},
{
name => 'device', type => 'String',
desc => '',
plat => ''
},
{
name => 'host', type => 'String',
desc => '',
plat => ''
},
{
name => 'time', type => 'Long',
desc => '',
plat => ''
},
],
);
my %cmds = (
@ -1013,7 +1034,7 @@ EOF
my %has_name_arg = map { $_, 1 } qw(FileSystemUsage FileAttrs DirStat
NetInterfaceConfig NetInterfaceStat);
my %proc_no_arg = map { $_, 1 } qw(stat);
my %get_not_impl = map { $_, 1 } qw(net_route net_connection
my %get_not_impl = map { $_, 1 } qw(net_route net_connection who
cpu_info file_system); #list funcs only
my %field_cache;

View File

@ -760,6 +760,37 @@ JNIEXPORT jstring SIGAR_JNI(NetConnection_getTypeString)
sigar_net_connection_type_get(type));
}
JNIEXPORT jobjectArray SIGAR_JNI(Sigar_getWhoList)
(JNIEnv *env, jobject sigar_obj)
{
int status;
unsigned int i;
sigar_who_list_t wholist;
jobjectArray whoarray;
jclass cls = SIGAR_FIND_CLASS("Who");
dSIGAR(NULL);
if ((status = sigar_who_list_get(sigar, &wholist)) != SIGAR_OK) {
sigar_throw_error(env, jsigar, status);
return NULL;
}
JAVA_SIGAR_INIT_FIELDS_WHO(cls);
whoarray = JENV->NewObjectArray(env, wholist.number, cls, 0);
for (i=0; i<wholist.number; i++) {
jobject info_obj = JENV->AllocObject(env, cls);
JAVA_SIGAR_SET_FIELDS_WHO(cls, info_obj,
wholist.data[i]);
JENV->SetObjectArrayElement(env, whoarray, i, info_obj);
}
sigar_who_list_destroy(sigar, &wholist);
return whoarray;
}
/* XXX perhaps it would be better to duplicate these strings
* in java land as static final so we dont create a new String
* everytime.