aboutsummaryrefslogtreecommitdiff
path: root/arm-probe
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-10-06 20:05:47 +0800
committerAndy Green <andy.green@linaro.org>2012-10-06 20:05:47 +0800
commit4198b5c4b498ef8c27949431466a0f86fe26d13f (patch)
tree603ec96104889a8fa1fe0fd5def57b4604f501a7 /arm-probe
parent7865c5bd9a6dca340b400b754b9d87e11d7367c2 (diff)
pass poll array management through callback
Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'arm-probe')
-rw-r--r--arm-probe/arm-probe.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/arm-probe/arm-probe.c b/arm-probe/arm-probe.c
index 1d8c6c7..b730d40 100644
--- a/arm-probe/arm-probe.c
+++ b/arm-probe/arm-probe.c
@@ -81,6 +81,28 @@ int get_stdin_line(char *buf, int maxlen)
return -1;
}
+void add_pollfd(struct aep_context *aep_context, int fd, int events)
+{
+ aep_context->pollfds[aep_context->count_pollfds].fd = fd;
+ aep_context->pollfds[aep_context->count_pollfds].events = events;
+ aep_context->pollfds[aep_context->count_pollfds++].revents = 0;
+}
+
+void remove_pollfd(struct aep_context *aep_context, int fd)
+{
+ int n;
+
+ for (n = 0; n < aep_context->count_pollfds; n++)
+ if (aep_context->pollfds[n].fd == fd) {
+ while (n < aep_context->count_pollfds) {
+ aep_context->pollfds[n] = aep_context->pollfds[n + 1];
+ n++;
+ }
+ aep_context->count_pollfds--;
+ }
+}
+
+
/*
* this is the callback where the results appear
*/
@@ -94,6 +116,16 @@ static void issue_samples(enum samples_actions sa, struct aep_channel *ch,
switch (sa) {
+ case AEPSA_ADD_POLLFD:
+ fprintf(stderr, "adding pollfd %d %d\n", (int)voltage, (int)current);
+ add_pollfd(&aep_context, (int)voltage, (int)current);
+ break;
+
+ case AEPSA_REMOVE_POLLFD:
+ fprintf(stderr, "remove pollfd %d\n", (int)voltage);
+ remove_pollfd(&aep_context, (int)voltage);
+ break;
+
case AEPSA_DATA_STARTING:
printf("#\n");
pos = 0;
@@ -411,10 +443,24 @@ int main(int argc, char *argv[])
* the main service loop
*/
- while (loop)
- if (service_aeps(&aep_context) < 0)
+ aep_context.poll_timeout_ms = 10;
+
+ while (loop) {
+
+ n = poll(aep_context.pollfds, aep_context.count_pollfds, aep_context.poll_timeout_ms);
+ if (n < 0)
+ return -1;
+
+ for (n = 0; n < aep_context.count_pollfds; n++)
+ if (aep_context.pollfds[n].revents)
+ if (service_aeps(&aep_context, aep_context.pollfds[n].fd) < 0)
+ loop = 0;
+
+ if (service_aeps(&aep_context, -1) < 0)
loop = 0;
+ }
+
/*
* we are finished if we reach here...
* append simple average to results if requested