b3c8d78cf758af6cffbacd0a8e5e43bee2e4c5b2
[firefly-linux-kernel-4.4.55.git] / tools / gator / daemon / Buffer.h
1 /**
2  * Copyright (C) ARM Limited 2013. 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 BUFFER_H
10 #define BUFFER_H
11
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <semaphore.h>
15
16 class Sender;
17
18 class Buffer {
19 public:
20         static const size_t MAXSIZE_PACK32 = 5;
21         static const size_t MAXSIZE_PACK64 = 10;
22
23         Buffer (int32_t core, int32_t buftype, const int size, sem_t *const readerSem);
24         ~Buffer ();
25
26         void write (Sender * sender);
27
28         int bytesAvailable () const;
29         void commit (const uint64_t time);
30         void check (const uint64_t time);
31
32         void frame ();
33
34         bool eventHeader (uint64_t curr_time);
35         bool eventTid (int tid);
36         void event (int32_t key, int32_t value);
37         void event64 (int64_t key, int64_t value);
38
39         void setDone ();
40         bool isDone () const;
41
42 private:
43         bool commitReady () const;
44         bool checkSpace (int bytes);
45
46         void packInt (int32_t x);
47         void packInt64 (int64_t x);
48
49         const int32_t core;
50         const int32_t buftype;
51         const int size;
52         int readPos;
53         int writePos;
54         int commitPos;
55         bool available;
56         bool done;
57         char *const buf;
58         uint64_t commitTime;
59         sem_t *const readerSem;
60
61         // Intentionally unimplemented
62         Buffer(const Buffer &);
63         Buffer &operator=(const Buffer &);
64 };
65
66 #endif // BUFFER_H