-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.c
207 lines (165 loc) · 4.63 KB
/
scheduler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (C) 2007 Christian Wieninger
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
The author can be reached at cwieninger@gmx.de
The project's page is at http://winni.vdr-developer.org/taskman
*/
/*
* taskman.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include <vdr/plugin.h>
#include <vdr/menu.h>
#include <getopt.h>
#include <string>
#include "scheduler.h"
#include "menu_tasks.h"
#include "taskmanager_thread.h"
#include "log.h"
#include "i18n.h"
#include "menu_setup.h"
#include "task.h"
cSchedulerConfig SchedulerConfig;
static const char *VERSION = "0.1.6";
static const char *DESCRIPTION = trNOOP("Job scheduler and manager");
static const char *MAINMENUENTRY = trNOOP("Job scheduler");
std::string cTaskLog::logDirectory = "";
char *ConfigDir = NULL;
// LogFile declaration and statics
cLogFile LogFile;
char *cLogFile::LogFileName = NULL;
int cLogFile::loglevellimit = 0;
cPluginScheduler::cPluginScheduler(void)
{
}
cPluginScheduler::~cPluginScheduler()
{
cTaskManagerThread::Exit();
if (ConfigDir) free(ConfigDir);
}
const char* cPluginScheduler::Version(void)
{
return VERSION;
}
const char* cPluginScheduler::Description(void)
{
return tr(DESCRIPTION);
}
const char *cPluginScheduler::MainMenuEntry(void)
{
if (SchedulerConfig.hidemenu)
return NULL;
else
{
int active = Tasks.CountActive();
if (active)
sprintf(mainmenuentry, "%s (%d %s)", tr(MAINMENUENTRY), Tasks.CountActive(), tr("active"));
else
sprintf(mainmenuentry, "%s", tr(MAINMENUENTRY));
return mainmenuentry;
}
}
const char *cPluginScheduler::CommandLineHelp(void)
{
return " -l file, --logfile=file to specify a specific logfile for scheduler\n"
" -v n, --verbose=n verbose level for logfile\n"
" -d direcoty, --logdirectory=directory save task logfile in the given directory";
}
bool cPluginScheduler::ProcessArgs(int argc, char *argv[])
{
static const struct option long_options[] = {
{ "logfile", required_argument, NULL, 'l' },
{ "verbose", required_argument, NULL, 'v' },
{ "logdirectory", required_argument, NULL, 'd' },
{ NULL }
};
int c=0,i=0;
while ((c = getopt_long(argc, argv, "l:v:d:", long_options, &i)) != -1) {
switch (c) {
case 'l':
cLogFile::LogFileName = optarg;
break;
case 'v':
cLogFile::loglevellimit = atoi(optarg);
break;
case 'd':
cTaskLog::logDirectory = optarg;
break;
}
}
return true;
}
bool cPluginScheduler::Initialize(void)
{
#if APIVERSNUM < 10507
RegisterI18n(Phrases);
#endif
return true;
}
bool cPluginScheduler::Start(void)
{
if (!ConfigDir)
ConfigDir = strdup(cPlugin::ConfigDirectory("scheduler"));
if (cLogFile::LogFileName)
LogFile.Open(cLogFile::LogFileName, Version());
else
LogFile.Open(AddDirectory(CONFIGDIR, "scheduler.log"), Version());
if (cTaskLog::logDirectory.empty())
cTaskLog::logDirectory = ConfigDir;
Tasks.Load(AddDirectory(CONFIGDIR, "tasks.conf"), true);
cTaskManagerThread::Init();
return true;
}
void cPluginScheduler::Stop(void)
{
}
void cPluginScheduler::Housekeeping(void)
{
}
void cPluginScheduler::MainThreadHook(void)
{
}
cString cPluginScheduler::Active(void)
{
return Tasks.Active();
}
time_t cPluginScheduler::WakeupTime(void)
{
return Tasks.NextWakeupTime();
}
cOsdObject *cPluginScheduler::MainMenuAction(void)
{
return new cMenuTasks();
}
cMenuSetupPage *cPluginScheduler::SetupMenu(void)
{
return new cMenuTaskmanSetup;
}
bool cPluginScheduler::SetupParse(const char *Name, const char *Value)
{
if (!strcasecmp(Name, "HideMenu")) SchedulerConfig.hidemenu = atoi(Value);
return true;
}
bool cPluginScheduler::Service(const char *Id, void *Data)
{
return false;
}
cSchedulerConfig::cSchedulerConfig(void)
{
hidemenu = 0;
}
VDRPLUGINCREATOR(cPluginScheduler); // Don't touch this!