summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2000-07-24 16:43:04 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2000-07-24 16:43:04 +0200
commit07d92eaee7d1ff37a6abfe873275b2f82a979271 (patch)
tree2ec763200083bc07820f099fc76ec079a6c91069 /recording.c
parent6602eb5c90210906273a5b9a15aa0d2d1d095a16 (diff)
downloadvdr-07d92eaee7d1ff37a6abfe873275b2f82a979271.tar.gz
vdr-07d92eaee7d1ff37a6abfe873275b2f82a979271.tar.bz2
Implemented 'summary' feature
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/recording.c b/recording.c
index 3e9df374..e37ccd85 100644
--- a/recording.c
+++ b/recording.c
@@ -4,14 +4,16 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: recording.c 1.11 2000/07/16 14:21:37 kls Exp $
+ * $Id: recording.c 1.12 2000/07/24 16:31:07 kls Exp $
*/
#define _GNU_SOURCE
#include "recording.h"
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "interface.h"
#include "tools.h"
@@ -20,6 +22,8 @@
#define DATAFORMAT "%4d-%02d-%02d.%02d:%02d.%02d.%02d" RECEXT
#define NAMEFORMAT "%s/%s/" DATAFORMAT
+#define SUMMARYFILESUFFIX "/summary.vdr"
+
#define FINDCMD "find %s -type d -name '%s' | sort -df"
#define DFCMD "df -m %s"
@@ -102,21 +106,14 @@ void AssertFreeDiskSpace(void)
// --- cRecording ------------------------------------------------------------
-cRecording::cRecording(const char *Name, time_t Start, int Priority, int LifeTime)
-{
- titleBuffer = NULL;
- fileName = NULL;
- name = strdup(Name);
- start = Start;
- priority = Priority;
- lifetime = LifeTime;
-}
-
cRecording::cRecording(cTimer *Timer)
{
titleBuffer = NULL;
fileName = NULL;
name = strdup(Timer->file);
+ summary = Timer->summary ? strdup(Timer->summary) : NULL;
+ if (summary)
+ strreplace(summary, '|', '\n');
start = Timer->StartTime();
priority = Timer->priority;
lifetime = Timer->lifetime;
@@ -130,6 +127,7 @@ cRecording::cRecording(const char *FileName)
char *p = strrchr(FileName, '/');
name = NULL;
+ summary = NULL;
if (p) {
time_t now = time(NULL);
struct tm t = *localtime(&now); // this initializes the time zone in 't'
@@ -143,6 +141,39 @@ cRecording::cRecording(const char *FileName)
name[p - FileName] = 0;
strreplace(name, '_', ' ');
}
+ // read an optional summary file:
+ char *SummaryFileName = NULL;
+ asprintf(&SummaryFileName, "%s%s", fileName, SUMMARYFILESUFFIX);
+ int f = open(SummaryFileName, O_RDONLY);
+ if (f >= 0) {
+ struct stat buf;
+ if (fstat(f, &buf) == 0) {
+ int size = buf.st_size;
+ summary = new char[size + 1]; // +1 for terminating 0
+ if (summary) {
+ int rbytes = read(f, summary, size);
+ if (rbytes >= 0) {
+ summary[rbytes] = 0;
+ if (rbytes != size)
+ esyslog(LOG_ERR, "%s: expected %d bytes but read %d", SummaryFileName, size, rbytes);
+ }
+ else {
+ LOG_ERROR_STR(SummaryFileName);
+ delete summary;
+ summary = NULL;
+ }
+
+ }
+ else
+ esyslog(LOG_ERR, "can't allocate %d byte of memory for summary file '%s'", size + 1, SummaryFileName);
+ close(f);
+ }
+ else
+ LOG_ERROR_STR(SummaryFileName);
+ }
+ else if (errno != ENOENT)
+ LOG_ERROR_STR(SummaryFileName);
+ delete SummaryFileName;
}
}
@@ -151,6 +182,7 @@ cRecording::~cRecording()
delete titleBuffer;
delete fileName;
delete name;
+ delete summary;
}
const char *cRecording::FileName(void)
@@ -181,6 +213,24 @@ const char *cRecording::Title(char Delimiter)
return titleBuffer;
}
+bool cRecording::WriteSummary(void)
+{
+ if (summary) {
+ char *SummaryFileName = NULL;
+ asprintf(&SummaryFileName, "%s%s", fileName, SUMMARYFILESUFFIX);
+ FILE *f = fopen(SummaryFileName, "w");
+ if (f) {
+ if (fputs(summary, f) < 0)
+ LOG_ERROR_STR(SummaryFileName);
+ fclose(f);
+ }
+ else
+ LOG_ERROR_STR(SummaryFileName);
+ delete SummaryFileName;
+ }
+ return true;
+}
+
bool cRecording::Delete(void)
{
bool result = true;