| 1 |
/* Time Based Text - Recorder |
|---|
| 2 |
* |
|---|
| 3 |
* (C) Copyright 2006 - 2007 Denis Rojo <jaromil@dyne.org> |
|---|
| 4 |
* Idea shared with Joan & Dirk <jodi@jodi.org> |
|---|
| 5 |
* |
|---|
| 6 |
* This source code is free software; you can redistribute it and/or |
|---|
| 7 |
* modify it under the terms of the GNU Public License as published |
|---|
| 8 |
* by the Free Software Foundation; either version 2 of the License, |
|---|
| 9 |
* or (at your option) any later version. |
|---|
| 10 |
* |
|---|
| 11 |
* This source code is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 14 |
* Please refer to the GNU Public License for more details. |
|---|
| 15 |
* |
|---|
| 16 |
* You should have received a copy of the GNU Public License along with |
|---|
| 17 |
* this source code; if not, write to: |
|---|
| 18 |
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 |
* |
|---|
| 20 |
*/ |
|---|
| 21 |
|
|---|
| 22 |
#ifndef __TIMEBASEDTEXT_H__ |
|---|
| 23 |
#define __TIMEBASEDTEXT_H__ |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
#include <time.h> |
|---|
| 27 |
#include <inttypes.h> |
|---|
| 28 |
#include <sys/time.h> |
|---|
| 29 |
|
|---|
| 30 |
#include <linklist.h> |
|---|
| 31 |
|
|---|
| 32 |
#define VERSION "v0.7 - tbt.dyne.org" |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
class RTClock; // ghost pointer for rtclock.h |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
/* |
|---|
| 39 |
This is the format of a single entry: |
|---|
| 40 |
|
|---|
| 41 |
int key - S-Lang key number (matches ASCII/ANSI) |
|---|
| 42 |
int sec - time delta seconds |
|---|
| 43 |
int usec - time delta 1/100 seconds */ |
|---|
| 44 |
class TBTEntry : public Entry { |
|---|
| 45 |
public: |
|---|
| 46 |
TBTEntry(); |
|---|
| 47 |
~TBTEntry(); |
|---|
| 48 |
|
|---|
| 49 |
uint64_t key; |
|---|
| 50 |
uint64_t msec; |
|---|
| 51 |
|
|---|
| 52 |
/* parse from *buf and return true on success */ |
|---|
| 53 |
bool parse_uint64(void *buf); |
|---|
| 54 |
/* parse from an ascii line and return true on success */ |
|---|
| 55 |
bool parse_ascii(char *buf); |
|---|
| 56 |
|
|---|
| 57 |
/* render in *buf and returns size in bytes */ |
|---|
| 58 |
int render_uint64(void *buf); |
|---|
| 59 |
int render_ascii(void *buf); |
|---|
| 60 |
int render_html(void *buf); |
|---|
| 61 |
|
|---|
| 62 |
}; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
class TBT { |
|---|
| 66 |
|
|---|
| 67 |
public: |
|---|
| 68 |
TBT(); |
|---|
| 69 |
~TBT(); |
|---|
| 70 |
|
|---|
| 71 |
int init(); |
|---|
| 72 |
|
|---|
| 73 |
// input functions: time based append of keys into a tbt recording |
|---|
| 74 |
|
|---|
| 75 |
void append(uint64_t key); ///< append a single key at the time this function is called |
|---|
| 76 |
|
|---|
| 77 |
int fdappend(int filedes, int keysize); ///< append keys read from a file descriptor |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
// playback functions: time based feed of keys loaded |
|---|
| 83 |
|
|---|
| 84 |
uint64_t getkey(); ///< wait the time and returns the next entry |
|---|
| 85 |
|
|---|
| 86 |
int position; ///< incremented by getkey calls |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
// loading functions: load a tbt recording for playback |
|---|
| 91 |
|
|---|
| 92 |
int load(char *filename); ///< load a .tbt recorded file |
|---|
| 93 |
//TODO: |
|---|
| 94 |
// int load_html(char *filename); |
|---|
| 95 |
int load_ascii(char *filename); |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
void clear(); ///< deletes all current keys and frees memory |
|---|
| 99 |
|
|---|
| 100 |
int save_bin(char *filename); |
|---|
| 101 |
int save_ascii(char *filename); |
|---|
| 102 |
int save_html(char *filename); |
|---|
| 103 |
|
|---|
| 104 |
Linklist *buffer; |
|---|
| 105 |
|
|---|
| 106 |
RTClock *clock; |
|---|
| 107 |
|
|---|
| 108 |
bool quit; |
|---|
| 109 |
|
|---|
| 110 |
private: |
|---|
| 111 |
|
|---|
| 112 |
void compute_delta(TBTEntry *tbt); |
|---|
| 113 |
|
|---|
| 114 |
uint64_t now; |
|---|
| 115 |
uint64_t past; |
|---|
| 116 |
|
|---|
| 117 |
bool rtc; // if /dev/rtc is present |
|---|
| 118 |
|
|---|
| 119 |
// POSIX time structures |
|---|
| 120 |
struct timespec psleep; // nanosleep (nanosec) |
|---|
| 121 |
struct timeval gettime; // gettimeofday (microsec) |
|---|
| 122 |
|
|---|
| 123 |
}; |
|---|
| 124 |
|
|---|
| 125 |
#endif |
|---|