tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / tools / gator / daemon / Driver.h
1 /**
2  * Copyright (C) ARM Limited 2013-2014. All rights reserved.
3  *
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
6  * published by the Free Software Foundation.
7  */
8
9 #ifndef DRIVER_H
10 #define DRIVER_H
11
12 #include <stdint.h>
13
14 #include "mxml/mxml.h"
15
16 class Buffer;
17 class Counter;
18
19 class DriverCounter {
20 public:
21         DriverCounter(DriverCounter *const next, const char *const name);
22         virtual ~DriverCounter();
23
24         DriverCounter *getNext() const { return mNext; }
25         const char *getName() const { return mName; }
26         int getKey() const { return mKey; }
27         bool isEnabled() const { return mEnabled; }
28         void setEnabled(const bool enabled) { mEnabled = enabled; }
29         virtual int64_t read() { return -1; }
30
31 private:
32         DriverCounter *const mNext;
33         const char *const mName;
34         const int mKey;
35         bool mEnabled;
36
37         // Intentionally unimplemented
38         DriverCounter(const DriverCounter &);
39         DriverCounter &operator=(const DriverCounter &);
40 };
41
42 class Driver {
43 public:
44         static Driver *getHead() { return head; }
45
46         virtual ~Driver() {}
47
48         // Returns true if this driver can manage the counter
49         virtual bool claimCounter(const Counter &counter) const = 0;
50         // Clears and disables all counters
51         virtual void resetCounters() = 0;
52         // Enables and prepares the counter for capture
53         virtual void setupCounter(Counter &counter) = 0;
54
55         // Performs any actions needed for setup or based on eventsXML
56         virtual void readEvents(mxml_node_t *const) {}
57         // Emits available counters
58         virtual int writeCounters(mxml_node_t *const root) const = 0;
59         // Emits possible dynamically generated events/counters
60         virtual void writeEvents(mxml_node_t *const) const {}
61
62         Driver *getNext() const { return next; }
63
64 protected:
65         Driver();
66
67 private:
68         static Driver *head;
69         Driver *next;
70
71         // Intentionally unimplemented
72         Driver(const Driver &);
73         Driver &operator=(const Driver &);
74 };
75
76 class SimpleDriver : public Driver {
77 public:
78         virtual ~SimpleDriver();
79
80         bool claimCounter(const Counter &counter) const;
81         bool countersEnabled() const;
82         void resetCounters();
83         void setupCounter(Counter &counter);
84         int writeCounters(mxml_node_t *root) const;
85
86 protected:
87         SimpleDriver() : mCounters(NULL) {}
88
89         DriverCounter *getCounters() const { return mCounters; }
90         void setCounters(DriverCounter *const counter) { mCounters = counter; }
91
92         DriverCounter *findCounter(const Counter &counter) const;
93
94 private:
95         DriverCounter *mCounters;
96
97         // Intentionally unimplemented
98         SimpleDriver(const SimpleDriver &);
99         SimpleDriver &operator=(const SimpleDriver &);
100 };
101
102 class PolledDriver : public SimpleDriver {
103 public:
104         virtual ~PolledDriver();
105
106         virtual void start() {}
107         virtual void read(Buffer *const buffer);
108
109 protected:
110         PolledDriver() {}
111
112 private:
113         // Intentionally unimplemented
114         PolledDriver(const PolledDriver &);
115         PolledDriver &operator=(const PolledDriver &);
116 };
117
118 #endif // DRIVER_H