diff options
Diffstat (limited to 'daemon/KMod.cpp')
-rw-r--r-- | daemon/KMod.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/daemon/KMod.cpp b/daemon/KMod.cpp index 559297f..9300002 100644 --- a/daemon/KMod.cpp +++ b/daemon/KMod.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * Copyright (C) ARM Limited 2013. All rights reserved. | 2 | * Copyright (C) ARM Limited 2013-2014. All rights reserved. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License version 2 as | 5 | * it under the terms of the GNU General Public License version 2 as |
@@ -12,9 +12,9 @@ | |||
12 | #include <dirent.h> | 12 | #include <dirent.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | 14 | ||
15 | #include "Collector.h" | ||
16 | #include "ConfigurationXML.h" | 15 | #include "ConfigurationXML.h" |
17 | #include "Counter.h" | 16 | #include "Counter.h" |
17 | #include "DriverSource.h" | ||
18 | #include "Logging.h" | 18 | #include "Logging.h" |
19 | 19 | ||
20 | // Claim all the counters in /dev/gator/events | 20 | // Claim all the counters in /dev/gator/events |
@@ -38,9 +38,9 @@ void KMod::resetCounters() { | |||
38 | continue; | 38 | continue; |
39 | snprintf(base, sizeof(base), "/dev/gator/events/%s", ent->d_name); | 39 | snprintf(base, sizeof(base), "/dev/gator/events/%s", ent->d_name); |
40 | snprintf(text, sizeof(text), "%s/enabled", base); | 40 | snprintf(text, sizeof(text), "%s/enabled", base); |
41 | Collector::writeDriver(text, 0); | 41 | DriverSource::writeDriver(text, 0); |
42 | snprintf(text, sizeof(text), "%s/count", base); | 42 | snprintf(text, sizeof(text), "%s/count", base); |
43 | Collector::writeDriver(text, 0); | 43 | DriverSource::writeDriver(text, 0); |
44 | } | 44 | } |
45 | closedir(dir); | 45 | closedir(dir); |
46 | } | 46 | } |
@@ -53,22 +53,22 @@ void KMod::setupCounter(Counter &counter) { | |||
53 | 53 | ||
54 | snprintf(text, sizeof(text), "%s/enabled", base); | 54 | snprintf(text, sizeof(text), "%s/enabled", base); |
55 | int enabled = true; | 55 | int enabled = true; |
56 | if (Collector::writeReadDriver(text, &enabled) || !enabled) { | 56 | if (DriverSource::writeReadDriver(text, &enabled) || !enabled) { |
57 | counter.setEnabled(false); | 57 | counter.setEnabled(false); |
58 | return; | 58 | return; |
59 | } | 59 | } |
60 | 60 | ||
61 | snprintf(text, sizeof(text), "%s/key", base); | 61 | snprintf(text, sizeof(text), "%s/key", base); |
62 | int key = 0; | 62 | int key = 0; |
63 | Collector::readIntDriver(text, &key); | 63 | DriverSource::readIntDriver(text, &key); |
64 | counter.setKey(key); | 64 | counter.setKey(key); |
65 | 65 | ||
66 | snprintf(text, sizeof(text), "%s/event", base); | 66 | snprintf(text, sizeof(text), "%s/event", base); |
67 | Collector::writeDriver(text, counter.getEvent()); | 67 | DriverSource::writeDriver(text, counter.getEvent()); |
68 | snprintf(text, sizeof(text), "%s/count", base); | 68 | snprintf(text, sizeof(text), "%s/count", base); |
69 | if (access(text, F_OK) == 0) { | 69 | if (access(text, F_OK) == 0) { |
70 | int count = counter.getCount(); | 70 | int count = counter.getCount(); |
71 | if (Collector::writeReadDriver(text, &count) && counter.getCount() > 0) { | 71 | if (DriverSource::writeReadDriver(text, &count) && counter.getCount() > 0) { |
72 | logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount()); | 72 | logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount()); |
73 | handleException(); | 73 | handleException(); |
74 | } | 74 | } |
@@ -80,23 +80,26 @@ void KMod::setupCounter(Counter &counter) { | |||
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | void KMod::writeCounters(mxml_node_t *root) const { | 83 | int KMod::writeCounters(mxml_node_t *root) const { |
84 | struct dirent *ent; | 84 | struct dirent *ent; |
85 | mxml_node_t *counter; | 85 | mxml_node_t *counter; |
86 | 86 | ||
87 | // counters.xml is simply a file listing of /dev/gator/events | 87 | // counters.xml is simply a file listing of /dev/gator/events |
88 | DIR* dir = opendir("/dev/gator/events"); | 88 | DIR* dir = opendir("/dev/gator/events"); |
89 | if (dir == NULL) { | 89 | if (dir == NULL) { |
90 | logg->logError(__FILE__, __LINE__, "Cannot create counters.xml since unable to read /dev/gator/events"); | 90 | return 0; |
91 | handleException(); | ||
92 | } | 91 | } |
93 | 92 | ||
93 | int count = 0; | ||
94 | while ((ent = readdir(dir)) != NULL) { | 94 | while ((ent = readdir(dir)) != NULL) { |
95 | // skip hidden files, current dir, and parent dir | 95 | // skip hidden files, current dir, and parent dir |
96 | if (ent->d_name[0] == '.') | 96 | if (ent->d_name[0] == '.') |
97 | continue; | 97 | continue; |
98 | counter = mxmlNewElement(root, "counter"); | 98 | counter = mxmlNewElement(root, "counter"); |
99 | mxmlElementSetAttr(counter, "name", ent->d_name); | 99 | mxmlElementSetAttr(counter, "name", ent->d_name); |
100 | ++count; | ||
100 | } | 101 | } |
101 | closedir(dir); | 102 | closedir(dir); |
103 | |||
104 | return count; | ||
102 | } | 105 | } |