Merge changes I1db3137b,I0f66144e
* changes: toolbox: reimplement watchprops using __system_property_foreach() libcutils: reimplement property_list() using __system_property_foreach()
This commit is contained in:
commit
e755dfd438
2 changed files with 79 additions and 50 deletions
|
|
@ -52,19 +52,28 @@ int property_get(const char *key, char *value, const char *default_value)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int property_list(void (*propfn)(const char *key, const char *value, void *cookie),
|
struct property_list_callback_data
|
||||||
void *cookie)
|
{
|
||||||
|
void (*propfn)(const char *key, const char *value, void *cookie);
|
||||||
|
void *cookie;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void property_list_callback(const prop_info *pi, void *cookie)
|
||||||
{
|
{
|
||||||
char name[PROP_NAME_MAX];
|
char name[PROP_NAME_MAX];
|
||||||
char value[PROP_VALUE_MAX];
|
char value[PROP_VALUE_MAX];
|
||||||
const prop_info *pi;
|
struct property_list_callback_data *data = cookie;
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
for(n = 0; (pi = __system_property_find_nth(n)); n++) {
|
__system_property_read(pi, name, value);
|
||||||
__system_property_read(pi, name, value);
|
data->propfn(name, value, data->cookie);
|
||||||
propfn(name, value, cookie);
|
}
|
||||||
}
|
|
||||||
return 0;
|
int property_list(
|
||||||
|
void (*propfn)(const char *key, const char *value, void *cookie),
|
||||||
|
void *cookie)
|
||||||
|
{
|
||||||
|
struct property_list_callback_data data = { propfn, cookie };
|
||||||
|
return __system_property_foreach(property_list_callback, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_SYSTEM_PROPERTY_SERVER)
|
#elif defined(HAVE_SYSTEM_PROPERTY_SERVER)
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,30 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <cutils/properties.h>
|
#include <cutils/properties.h>
|
||||||
|
#include <cutils/hashmap.h>
|
||||||
|
|
||||||
#include <sys/atomics.h>
|
#include <sys/atomics.h>
|
||||||
|
|
||||||
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
||||||
#include <sys/_system_properties.h>
|
#include <sys/_system_properties.h>
|
||||||
|
|
||||||
typedef struct pwatch pwatch;
|
static int str_hash(void *key)
|
||||||
|
|
||||||
struct pwatch
|
|
||||||
{
|
{
|
||||||
const prop_info *pi;
|
return hashmapHash(key, strlen(key));
|
||||||
unsigned serial;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static pwatch watchlist[1024];
|
static bool str_equals(void *keyA, void *keyB)
|
||||||
|
{
|
||||||
static void announce(const prop_info *pi)
|
return strcmp(keyA, keyB) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void announce(char *name, char *value)
|
||||||
{
|
{
|
||||||
char name[PROP_NAME_MAX];
|
|
||||||
char value[PROP_VALUE_MAX];
|
|
||||||
char *x;
|
char *x;
|
||||||
|
|
||||||
__system_property_read(pi, name, value);
|
|
||||||
|
|
||||||
for(x = value; *x; x++) {
|
for(x = value; *x; x++) {
|
||||||
if((*x < 32) || (*x > 127)) *x = '.';
|
if((*x < 32) || (*x > 127)) *x = '.';
|
||||||
}
|
}
|
||||||
|
|
@ -34,42 +32,64 @@ static void announce(const prop_info *pi)
|
||||||
fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
|
fprintf(stderr,"%10d %s = '%s'\n", (int) time(0), name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_to_watchlist(Hashmap *watchlist, const char *name,
|
||||||
|
const prop_info *pi)
|
||||||
|
{
|
||||||
|
char *key = strdup(name);
|
||||||
|
unsigned *value = malloc(sizeof(unsigned));
|
||||||
|
if (!key || !value)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
*value = __system_property_serial(pi);
|
||||||
|
hashmapPut(watchlist, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void populate_watchlist(const prop_info *pi, void *cookie)
|
||||||
|
{
|
||||||
|
Hashmap *watchlist = cookie;
|
||||||
|
char name[PROP_NAME_MAX];
|
||||||
|
char value_unused[PROP_VALUE_MAX];
|
||||||
|
|
||||||
|
__system_property_read(pi, name, value_unused);
|
||||||
|
add_to_watchlist(watchlist, name, pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_watchlist(const prop_info *pi, void *cookie)
|
||||||
|
{
|
||||||
|
Hashmap *watchlist = cookie;
|
||||||
|
char name[PROP_NAME_MAX];
|
||||||
|
char value[PROP_VALUE_MAX];
|
||||||
|
unsigned *serial;
|
||||||
|
|
||||||
|
__system_property_read(pi, name, value);
|
||||||
|
serial = hashmapGet(watchlist, name);
|
||||||
|
if (!serial) {
|
||||||
|
add_to_watchlist(watchlist, name, pi);
|
||||||
|
announce(name, value);
|
||||||
|
} else {
|
||||||
|
unsigned tmp = __system_property_serial(pi);
|
||||||
|
if (*serial != tmp) {
|
||||||
|
*serial = tmp;
|
||||||
|
announce(name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int watchprops_main(int argc, char *argv[])
|
int watchprops_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned serial = 0;
|
unsigned serial = 0;
|
||||||
unsigned count;
|
unsigned count = 0;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
for(n = 0; n < 1024; n++) {
|
Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals);
|
||||||
watchlist[n].pi = __system_property_find_nth(n);
|
if (!watchlist)
|
||||||
if (watchlist[n].pi == 0)
|
|
||||||
break;
|
|
||||||
watchlist[n].serial = __system_property_serial(watchlist[n].pi);
|
|
||||||
}
|
|
||||||
|
|
||||||
count = n;
|
|
||||||
if (count == 1024)
|
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
__system_property_foreach(populate_watchlist, watchlist);
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
serial = __system_property_wait_any(serial);
|
serial = __system_property_wait_any(serial);
|
||||||
while(count < 1024){
|
__system_property_foreach(update_watchlist, watchlist);
|
||||||
watchlist[count].pi = __system_property_find_nth(count);
|
|
||||||
if (watchlist[count].pi == 0)
|
|
||||||
break;
|
|
||||||
watchlist[count].serial = __system_property_serial(watchlist[n].pi);
|
|
||||||
announce(watchlist[count].pi);
|
|
||||||
count++;
|
|
||||||
if(count == 1024) exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(n = 0; n < count; n++){
|
|
||||||
unsigned tmp = __system_property_serial(watchlist[n].pi);
|
|
||||||
if(watchlist[n].serial != tmp) {
|
|
||||||
announce(watchlist[n].pi);
|
|
||||||
watchlist[n].serial = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue