OBJS = $(PLUGIN).o dsock.o mvpserver.o udpreplier.o mvpclient.o tcp.o \
transceiver.o remux/ts2ps.o remux/ts2es.o remux/tsremux.o ringbuffer.o \
- recplayer.o config.o
+ recplayer.o config.o log.o
libdvbmpeg/libdvbmpegtools.a: libdvbmpeg/*.c libdvbmpeg/*.cc libdvbmpeg/*.h libdvbmpeg/*.hh
%.o: %.c
$(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) -o $@ $<
-
+
# Dependencies:
MAKEDEP = g++ -MM -MG
{
initted = 0;
lastLineLength = 0;
+ log = Log::getInstance();
}
int Config::init(char* takeFileName)
if (strlen(takeFileName) > (MAX_FILENAME_LENGTH - 1))
{
- printf("Config error: Config filename too long\n");
+ log->log("Config", Log::DEBUG, "Config error: Config filename too long");
return 0;
}
file = fopen(fileName, "w");
if (!file)
{
- printf("Config error: Could not access config file\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not access config file");
return 0;
}
}
if (!initted) return 0;
if (pthread_mutex_lock(&fileLock))
{
- printf("Config error: Could not get lock\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not get lock");
return 0;
}
if (!initted)
{
- printf("Config error: Initted 0 after lock\n");
+ log->log("Config", Log::DEBUG, "Config error: Initted 0 after lock");
pthread_mutex_unlock(&fileLock);
return 0;
}
file = fopen(fileName, "r");
if (!file)
{
- printf("Config error: Could not open config file\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not open config file");
pthread_mutex_unlock(&fileLock);
return 0;
}
int Config::readLine()
{
- if (!initted || !file) { printf("1\n"); return 0; }
- if (!fgets(buffer, BUFFER_LENGTH-1, file)) { printf("2\n"); return 0; }
+ if (!initted || !file) { log->log("Config", Log::DEBUG, "1"); return 0; }
+ if (!fgets(buffer, BUFFER_LENGTH-1, file)) { log->log("Config", Log::DEBUG, "2"); return 0; }
lastLineLength = strlen(buffer);
- printf("buffer before trim: '%s'\n", buffer);
+ log->log("Config", Log::DEBUG, "buffer before trim: '%s'", buffer);
trim(buffer);
- printf("buffer after trim: '%s'\n", buffer);
+ log->log("Config", Log::DEBUG, "buffer after trim: '%s'", buffer);
return 1;
}
if (!findSection(section))
{
closeFile();
- printf("Config error: Section %s not found\n", section);
+ log->log("Config", Log::DEBUG, "Config error: Section %s not found", section);
return 0;
}
if (!findKey(key))
{
closeFile();
- printf("Config error: Key %s not found\n", key);
+ log->log("Config", Log::DEBUG, "Config error: Key %s not found", key);
return 0;
}
if (!newFile)
{
closeFile();
- printf("Config error: Could not write temp config file\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not write temp config file");
return 0;
}
if (!newFile)
{
closeFile();
- printf("Config error: Could not write temp config file\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not write temp config file");
return 0;
}
if (!newFile)
{
closeFile();
- printf("Config error: Could not write temp config file\n");
+ log->log("Config", Log::DEBUG, "Config error: Could not write temp config file");
return 0;
}
if (!initted || !file) return 0;
if (strlen(section) > (BUFFER_LENGTH-2))
{
- printf("Config error: Section given exceeds max length\n");
+ log->log("Config", Log::DEBUG, "Config error: Section given exceeds max length");
return 0;
}
while(readLine())
{
- printf("to find '%s' this line '%s'\n", toFind, buffer);
+ log->log("Config", Log::DEBUG, "to find '%s' this line '%s'", toFind, buffer);
if (!strcmp(toFind, buffer)) return 1;
}
return 0;
if (strlen(key) > (BUFFER_LENGTH-1))
{
- printf("Config error: Key given exceeds max length\n");
+ log->log("Config", Log::DEBUG, "Config error: Key given exceeds max length");
return 0;
}
if (!findSection(section))
{
closeFile();
- printf("Config error: Section %s not found\n", section);
+ log->log("Config", Log::DEBUG, "Config error: Section %s not found", section);
return 0;
}
if (!findKey(key))
{
closeFile();
- printf("Config error: Key %s not found\n", key);
+ log->log("Config", Log::DEBUG, "Config error: Key %s not found", key);
return 0;
}
if (!findSection(section))
{
closeFile();
- printf("Config error: Section %s not found\n", section);
+ log->log("Config", Log::DEBUG, "Config error: Section %s not found", section);
return 0;
}
if (!findKey(key))
{
closeFile();
- printf("Config error: Key %s not found\n", key);
+ log->log("Config", Log::DEBUG, "Config error: Key %s not found", key);
return 0;
}
*failure = 0;
if (!findSection(section))
{
closeFile();
- printf("Config error: Section %s not found\n", section);
+ log->log("Config", Log::DEBUG, "Config error: Section %s not found", section);
return 0;
}
if (!findKey(key))
{
closeFile();
- printf("Config error: Key %s not found\n", key);
+ log->log("Config", Log::DEBUG, "Config error: Key %s not found", key);
return 0;
}
*failure = 0;
if (!findSection(section))
{
closeFile();
- printf("Config error: Section %s not found\n", section);
+ log->log("Config", Log::DEBUG, "Config error: Section %s not found", section);
return 0;
}
if (!findKey(key))
{
closeFile();
- printf("Config error: Key %s not found\n", key);
+ log->log("Config", Log::DEBUG, "Config error: Key %s not found", key);
return 0;
}
#include <pthread.h>
#include <ctype.h>
+#include "log.h"
+
#define MAX_FILENAME_LENGTH 500
#define BUFFER_LENGTH 1500
pthread_mutex_t fileLock;
int initted;
int lastLineLength;
+ Log* log;
char fileName[MAX_FILENAME_LENGTH];
char fileNameTemp[MAX_FILENAME_LENGTH];
{
myPort = port;
addrlen = sizeof(struct sockaddr);
+ log = Log::getInstance();
+ initted = 0;
if ((socketnum = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- { perror("socket"); exit(1); }
+ {
+ log->log("UDP", Log::CRIT, "Socket error");
+ return;
+ }
myAddr.sin_family = AF_INET; // host byte order
myAddr.sin_port = htons(myPort); // short, network byte order
myAddr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP
memset(&(myAddr.sin_zero), 0, 8); // zero the rest of the struct
if (bind(socketnum, (struct sockaddr *)&myAddr, addrlen) == -1)
- { perror("bind"); printf(" %s ", strerror(errno)); exit(1); }
+ {
+ log->log("UDP", Log::CRIT, "Bind error");
+ close(socketnum);
+ return;
+ }
+ initted = 1;
FD_ZERO(&readfds);
FD_SET(socketnum, &readfds);
DatagramSocket::~DatagramSocket()
{
- close(socketnum);
+ if (initted) close(socketnum);
+ initted = 0;
}
unsigned char DatagramSocket::waitforMessage(unsigned char how)
{
+ if (!initted) return 0;
+
/* how = 0 - block
how = 1 - start new wait
how = 2 - continue wait
FD_ZERO(&readfds);
FD_SET(socketnum, &readfds);
- if (select(socketnum + 1, &readfds, NULL, NULL, passToSelect) <= 0)
- { return 1; }
+ if (select(socketnum + 1, &readfds, NULL, NULL, passToSelect) <= 0) return 1;
- if ((mlength = recvfrom(socketnum, buf, MAXBUFLEN, 0,
- (struct sockaddr *)&theirAddr, &addrlen)) == -1)
- { perror("recvfrom"); return 0; }
+ if ((mlength = recvfrom(socketnum, buf, MAXBUFLEN, 0, (struct sockaddr *)&theirAddr, &addrlen)) == -1)
+ {
+ log->log("UDP", Log::DEBUG, "recvfrom error");
+ return 0;
+ }
else
{
memset(&buf[mlength], 0, MAXBUFLEN - mlength);
strcpy(fromIPA, inet_ntoa(theirAddr.sin_addr));
fromPort = ntohs(theirAddr.sin_port);
-
- if (DSOCKDEBUG)
- {
- printf("%s:%i\tIN %i\t", fromIPA, fromPort, mlength);
- int k;
- for(k = 0; k < mlength; k++)
- printf("%u ", (unsigned char)buf[k]);
- printf("\n");
- }
+ log->log("UDP", Log::DEBUG, "%s:%i received length %i", fromIPA, fromPort, mlength);
return 2;
}
void DatagramSocket::send(char *ipa, short port, char *message, int length)
{
- if (DSOCKDEBUG)
- {
- printf("%s:%i\tOUT %i\t", ipa, port, length);
- int k;
- uchar l;
- for (k = 0; k < length; k++)
- { l = (uchar)message[k]; printf("%u ", l); }
- }
-
int sentLength = 0;
theirAddr.sin_family = AF_INET; // host byte order
theirAddr.sin_addr = tad; // address
memset(&(theirAddr.sin_zero), 0, 8); // zero the rest of the struct
- unsigned char crypt[MAXBUFLEN];
- memcpy(crypt, message, length);
-
- sentLength = sendto(socketnum, crypt, length, 0, (struct sockaddr *)&theirAddr, addrlen);
+ sentLength = sendto(socketnum, message, length, 0, (struct sockaddr *)&theirAddr, addrlen);
if (sentLength == length)
{
- printf(" GOOD\n");
+ log->log("UDP", Log::DEBUG, "%s:%i sent length %i", ipa, port, length);
+ return;
}
- else
+
+ log->log("UDP", Log::DEBUG, "%s:%i send failed %i", ipa, port, length);
+
+ sentLength = sendto(socketnum, message, length, 0, (struct sockaddr *)&theirAddr, addrlen);
+ if (sentLength == length)
{
- printf(" --BAD--"); fflush(stdout);
- sentLength = sendto(socketnum, crypt, length, 0, (struct sockaddr *)&theirAddr, addrlen);
- if (sentLength == length)
- printf(" GOOD\n");
- else
- {
- printf(" -#-FAILED-#-\n");
-
- if (DSOCKDEBUG && (sentLength != length))
- {
- printf("--------------\n");
- printf("Sendto failure\n");
- printf("--------------\n");
- printf("%s:%i\tOUT %i %i ...\n", ipa, port, length, sentLength);
- perror("Perror reports");
- printf("errno value: %d\n", errno);
- printf("errno translated: %s\n", strerror(errno));
- // printf("h_errno value: %d\n", h_errno);
- // printf("\nActual address: %s\n", inet_ntoa(tad));
- // printf("Actual port: %i\n", ntohs(theirAddr.sin_port));
- printf("continuing...\n\n");
- }
- }
+ log->log("UDP", Log::DEBUG, "%s:%i sent length %i 2nd try", ipa, port, length);
+ return;
}
+
+ log->log("UDP", Log::DEBUG, "%s:%i send failed %i 2nd try", ipa, port, length);
}
#include <string.h>
#include <errno.h>
+#include "log.h"
+
#define MAXBUFLEN 2000
-const char DSOCKDEBUG = 1;
+const char DSOCKDEBUG = 0;
typedef unsigned char uchar;
class DatagramSocket
void send(char *, short, char *, int); // send wants: IP Address ddn style, port,
// data, length of data
private:
+ Log* log;
+ int initted;
int socketnum; // Socket descriptor
short myPort; // My port number
struct sockaddr_in myAddr; // My address
cm = NULL;
rp = NULL;
recordingManager = NULL;
+ log = Log::getInstance();
// Get IP address of client for config module
else
{
ipa[0] = '\0';
- printf("Cannot get peer name!\n");
+ log->log("Client", Log::DEBUG, "Cannot get peer name!");
}
const char* configDir = cPlugin::ConfigDirectory();
if (!configDir)
{
- printf("No config dir!\n");
+ log->log("Client", Log::DEBUG, "No config dir!");
return;
}
snprintf(configFileName, PATH_MAX - strlen(configDir) - strlen(ipa) - 20, "%s/vomp-%s.conf", configDir, ipa);
config.init(configFileName);
- printf("Config file name: %s\n", configFileName);
+ log->log("Client", Log::DEBUG, "Config file name: %s", configFileName);
// processGetChannelSchedule(NULL, 0);
-// printf("here\n");
//test();
}
MVPClient::~MVPClient()
{
- printf("MVP client destructor\n");
+ log->log("Client", Log::DEBUG, "MVP client destructor");
if (cm)
{
cm->Stop();
{
if (!channel->GroupSep())
{
- printf("Looking for channel %lu::: number: %i name: '%s'\n", channelNumber, channel->Number(), channel->Name());
+ log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
if (channel->Number() == (int)channelNumber)
{
#else
int apid1 = channel->Apid(0);
#endif
- printf("Found channel number %lu, vpid = %i, apid1 = %i\n", channelNumber, vpid, apid1);
+ log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
return channel;
}
}
if (!channel)
{
- printf("Channel not found\n");
+ log->log("Client", Log::DEBUG, "Channel not found");
}
return channel;
*(unsigned long*)&sendBuffer[4] = htonl(ul);
tcp.sendPacket(sendBuffer, 8);
- printf("written ULONG %lu\n", ul);
+ log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
}
void MVPClientStartThread(void* arg)
int MVPClient::run()
{
if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
- printf("MVPClient run success\n");
+ log->log("Client", Log::DEBUG, "MVPClient run success");
return 1;
}
while(1)
{
- printf("starting wait\n");
+ log->log("Client", Log::DEBUG, "Waiting");
buffer = (unsigned char*)tcp.receivePacket();
- printf("back from wait\n");
+ log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
if (buffer == NULL)
{
- printf("Detected connection closed\n");
+ log->log("Client", Log::DEBUG, "Detected connection closed");
break;
}
*(signed int*)&sendBuffer[8] = htonl(timeOffset);
tcp.sendPacket(sendBuffer, 12);
- printf("written login reply\n");
+ log->log("Client", Log::DEBUG, "written login reply");
}
void MVPClient::processGetRecordingsList(unsigned char* data, int length)
*(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- printf("recorded size as %u\n", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
- printf("Written list\n");
+ log->log("Client", Log::DEBUG, "Written list");
}
void MVPClient::processDeleteRecording(unsigned char* data, int length)
cRecording* recording = Recordings.GetByName((char*)data);
- printf("recording pointer %p\n", recording);
+ log->log("Client", Log::DEBUG, "recording pointer %p", recording);
if (recording)
{
- printf("deleting recording: %s\n", recording->Name());
+ log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
recording->Delete();
sendULONG(1);
}
cRecording *recording = Recordings.GetByName((char*)data);
- printf("recording pointer %p\n", recording);
+ log->log("Client", Log::DEBUG, "recording pointer %p", recording);
if (recording)
{
#else
const cRecordingInfo *Info = recording->Info();
point = (char*)Info->ShortText();
- printf("info pointer %p\nsummary pointer %p\n", Info, point);
+ log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point);
if (isempty(point))
{
point = (char*)Info->Description();
- printf("description pointer %p\n", point);
+ log->log("Client", Log::DEBUG, "description pointer %p", point);
}
#endif
strcpy((char*)&sendBuffer[count], point);
count += strlen(point) + 1;
*(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- printf("recorded size as %u\n", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
- printf("Written summary\n");
+ log->log("Client", Log::DEBUG, "Written summary");
}
if (!channel->GroupSep() && !channel->Ca(0))
#endif
{
- printf("name: '%s'\n", channel->Name());
+ log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
if (channel->Vpid()) type = 1;
#if VDRVERSNUM < 10300
*(unsigned long*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
- printf("recorded size as %u\n", ntohl(*(unsigned long*)&sendBuffer[0]));
+ log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(unsigned long*)&sendBuffer[0]));
tcp.sendPacket(sendBuffer, count);
delete[] sendBuffer;
- printf("Written channels list\n");
+ log->log("Client", Log::DEBUG, "Written channels list");
}
void MVPClient::processStartStreamingChannel(unsigned char* data, int length)
{
- printf("length = %i\n", length);
+ log->log("Client", Log::DEBUG, "length = %i", length);
unsigned long channelNumber = ntohl(*(unsigned long*)data);
cChannel* channel = channelFromNumber(channelNumber);
return;
}
-// MVPReceiver* m = new MVPReceiver(channel->Vpid(), channel->Apid1());
- cm = new cMediamvpTransceiver(channel, 0, 0, cDevice::ActualDevice());
- cDevice::ActualDevice()->AttachReceiver(cm);
- //cDevice::ActualDevice()->SwitchChannel(channel, false);
- sendULONG(1);
+// static cDevice *GetDevice(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL);
+ ///< Returns a device that is able to receive the given Channel at the
+ ///< given Priority.
+ ///< See ProvidesChannel() for more information on how
+ ///< priorities are handled, and the meaning of NeedsDetachReceivers.
+
+ bool NeedsDetachReceivers;
+ cDevice* device = cDevice::GetDevice(channel, 0, &NeedsDetachReceivers);
+ if (!device)
+ {
+ log->log("Client", Log::DEBUG, "No device found to receive this channel at this priority");
+ sendULONG(0);
+ }
+ else if (NeedsDetachReceivers)
+ {
+ // can't really happen since we stream with priority zero. if a rec has pri zero maybe
+ log->log("Client", Log::DEBUG, "Needs detach receivers");
+ sendULONG(0);
+ }
+ else
+ {
+ cm = new cMediamvpTransceiver(channel, 0, 0, device);
+ device->AttachReceiver(cm);
+ sendULONG(1);
+ }
+
+
+////// MVPReceiver* m = new MVPReceiver(channel->Vpid(), channel->Apid1());
+// cm = new cMediamvpTransceiver(channel, 0, 0, cDevice::ActualDevice());
+// cDevice::ActualDevice()->AttachReceiver(cm);
+//// //cDevice::ActualDevice()->SwitchChannel(channel, false);
+
+// sendULONG(1);
}
void MVPClient::processStopStreaming(unsigned char* data, int length)
{
- printf("STOP STREAMING RECEIVED\n");
+ log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
if (cm)
{
delete cm;
{
if (!cm && !rp)
{
- printf("Get block called when no streaming happening!\n");
+ log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
return;
}
ULLONG position = ntohll(*(ULLONG*)data);
- printf("getblock called for position = %llu\n", position);
-
data += sizeof(ULLONG);
-
unsigned long amount = ntohl(*(unsigned long*)data);
- printf("getblock called for length = %lu\n", amount);
+
+ log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
unsigned char sendBuffer[amount + 4];
unsigned long amountReceived = 0; // compiler moan.
if (cm)
{
- printf("getting from live\n");
+ log->log("Client", Log::DEBUG, "getting from live");
amountReceived = cm->getBlock(&sendBuffer[4], amount);
}
else if (rp)
{
- printf("getting from recording\n");
+ log->log("Client", Log::DEBUG, "getting from recording");
amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
}
*(unsigned long*)&sendBuffer[0] = htonl(amountReceived);
- printf("sendpacket go\n");
tcp.sendPacket(sendBuffer, amountReceived + 4);
- printf("written ok %lu\n", amountReceived);
+ log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
}
void MVPClient::processStartStreamingRecording(unsigned char* data, int length)
cRecording* recording = recordingManager->GetByName((char*)data);
- printf("recording pointer %p\n", recording);
+ log->log("Client", Log::DEBUG, "recording pointer %p", recording);
if (recording)
{
*(ULLONG*)&sendBuffer[4] = htonll(rp->getTotalLength());
tcp.sendPacket(sendBuffer, 12);
- printf("written totalLength\n");
+ log->log("Client", Log::DEBUG, "written totalLength");
}
else
{
void MVPClient::processGetChannelSchedule(unsigned char* data, int length)
{
ULONG channelNumber = ntohl(*(ULLONG*)data);
- printf("get schedule called for channel %lu\n", channelNumber);
+ log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
cChannel* channel = channelFromNumber(channelNumber);
if (!channel)
unsigned char sendBuffer[4];
*(unsigned long*)&sendBuffer[0] = htonl(0);
tcp.sendPacket(sendBuffer, 4);
- printf("written null\n");
+ log->log("Client", Log::DEBUG, "written null");
return;
}
*(unsigned long*)&sendBuffer[0] = htonl(4);
*(unsigned long*)&sendBuffer[4] = htonl(0);
tcp.sendPacket(sendBuffer, 8);
- printf("written 0\n");
+ log->log("Client", Log::DEBUG, "written 0");
return;
}
*(unsigned long*)&sendBuffer[0] = htonl(4);
*(unsigned long*)&sendBuffer[4] = htonl(1);
tcp.sendPacket(sendBuffer, 8);
- printf("written 1\n");
+ log->log("Client", Log::DEBUG, "written 1");
}
// if the last string (value) doesnt have null terminator, give up
if (buffer[length - 1] != '\0') return;
- printf("Config save:\n%s\n%s\n%s\n", section, key, value);
+ log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
if (config.setValueString(section, key, value))
{
sendULONG(1);
strcpy((char*)&sendBuffer[4], value);
tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
- printf("Written config load packet\n");
+ log->log("Client", Log::DEBUG, "Written config load packet");
delete[] value;
}
else
*(unsigned long*)&sendBuffer[4] = htonl(0);
tcp.sendPacket(sendBuffer, 8);
- printf("Written config load failed packet\n");
+ log->log("Client", Log::DEBUG, "Written config load failed packet");
}
}
void MVPClient::cleanConfig()
{
- printf("Clean config\n");
+ log->log("Client", Log::DEBUG, "Clean config");
cRecordings Recordings;
Recordings.Load();
char* position = resumes;
for(int k = 0; k < numReturns; k++)
{
- printf("EXAMINING: %i %i %p %s\n", k, numReturns, position, position);
+ log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
cRecording* recording = Recordings.GetByName(position);
if (!recording)
{
// doesn't exist anymore
- printf("Found a recording that doesn't exist anymore\n");
+ log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
config.deleteValue("ResumeData", position);
}
else
{
- printf("This recording still exists\n");
+ log->log("Client", Log::DEBUG, "This recording still exists");
}
position += strlen(position) + 1;
cMediamvpTransceiver* cm;
cRecordings* recordingManager;
RecPlayer* rp;
+ Log* log;
void processLogin(unsigned char* buffer, int length);
void processGetRecordingsList(unsigned char* data, int length);
{
if (!running) return 0;
+ log.shutdown();
udpr.stop();
pthread_cancel(runThread);
{
if (running) return 1;
-// logger.init(Log::DEBUG, "/tmp/vompserver.log");
+ log.init(Log::DEBUG, "/tmp/vompserver.log", 0);
if (udpr.run() == 0) return 0;
if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPServerStartThread, (void *)this) == -1) return 0;
- printf("MVPServer run success\n");
+ log.log("MVPServer", Log::DEBUG, "MVPServer run success");
return 1;
}
listeningSocket = socket(AF_INET, SOCK_STREAM, 0);
if (listeningSocket < 0)
{
- printf("Could not get TCP socket in vompserver\n");
+ log.log("MVPServer", Log::DEBUG, "Could not get TCP socket in vompserver");
return;
}
if (bind(listeningSocket,(struct sockaddr *)&address,sizeof(address)) < 0)
{
- printf("Could not bind to socket in vompserver\n");
+ log.log("MVPServer", Log::DEBUG, "Could not bind to socket in vompserver");
close(listeningSocket);
return;
}
pthread_t runThread;
int running;
+ Log log;
UDPReplier udpr;
int listeningSocket;
};
file = NULL;
totalLength = 0;
lastPosition = 0;
+ log = Log::getInstance();
recording = rec;
// FIXME find out max file path / name lengths
for(int i = 1; i < 1001; i++)
{
snprintf(fileName, 2047, "%s/%03i.vdr", rec->FileName(), i);
- printf("FILENAME: %s\n", fileName);
+ log->log("RecPlayer", Log::DEBUG, "FILENAME: %s", fileName);
file = fopen(fileName, "r");
if (file)
{
fseek(file, 0, SEEK_END);
totalLength += ftell(file);
- printf("File %i found, totalLength now %llu\n", i, totalLength);
+ log->log("RecPlayer", Log::DEBUG, "File %i found, totalLength now %llu", i, totalLength);
segments[i]->end = totalLength;
fclose(file);
}
RecPlayer::~RecPlayer()
{
- printf("RecPlayer destructor\n");
+ log->log("RecPlayer", Log::DEBUG, "destructor");
int i = 1;
while(segments[i++]) delete segments[i];
if (file) fclose(file);
char fileName[2048];
snprintf(fileName, 2047, "%s/%03i.vdr", recording->FileName(), index);
- printf("openFile called for index %i string:%s\n", index, fileName);
+ log->log("RecPlayer", Log::DEBUG, "openFile called for index %i string:%s", index, fileName);
file = fopen(fileName, "r");
if (!file)
{
- printf("file failed to open\n");
+ log->log("RecPlayer", Log::DEBUG, "file failed to open");
fileOpen = 0;
return 0;
}
{
if ((amount > totalLength) || (amount > 100000))
{
- printf("Amount %lu requested and rejected\n", amount);
+ log->log("RecPlayer", Log::DEBUG, "Amount %lu requested and rejected", amount);
return 0;
}
if (position >= totalLength)
{
- printf("Client asked for data starting past end of recording!\n");
+ log->log("RecPlayer", Log::DEBUG, "Client asked for data starting past end of recording!");
return 0;
}
if ((position + amount) > totalLength)
{
- printf("Client asked for some data past the end of recording, adjusting amount\n");
+ log->log("RecPlayer", Log::DEBUG, "Client asked for some data past the end of recording, adjusting amount");
amount = totalLength - position;
}
#include <vdr/recording.h>
#include "defines.h"
+#include "log.h"
class Segment
{
cRecording* getCurrentRecording();
private:
+ Log* log;
cRecording* recording;
FILE* file;
int fileOpen;
TCP::TCP(int tsocket)
{
+ log = Log::getInstance();
sock = -1;
connected = 0;
readTimeoutEnabled = 1;
close(sock);
sock = -1;
connected = 0;
- printf("TCP has closed socket\n");
+ log->log("TCP", Log::DEBUG, "TCP has closed socket");
}
option = 1;
s1 = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
- printf("SO_KEEPALIVE = %i\n", s1);
+ log->log("TCP", Log::DEBUG, "SO_KEEPALIVE = %i", s1);
option = timeOut;
s2 = setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &option, sizeof(option));
- printf("TCP_KEEPIDLE = %i\n", s2);
+ log->log("TCP", Log::DEBUG, "TCP_KEEPIDLE = %i", s2);
s3 = setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &option, sizeof(option));
- printf("TCP_KEEPINTVL = %i\n", s3);
+ log->log("TCP", Log::DEBUG, "TCP_KEEPINTVL = %i", s3);
option = 2;
s4 = setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &option, sizeof(option));
- printf("TCP_KEEPCNT = %i\n", s4);
+ log->log("TCP", Log::DEBUG, "TCP_KEEPCNT = %i", s4);
if (s1 || s2 || s3 || s4) return 0;
return 1;
return NULL;
}
- dump((unsigned char*)buffer, packetLength);
+// dump((unsigned char*)buffer, packetLength);
dataLength = packetLength;
return buffer;
if (success < 1)
{
cleanup();
- printf("TCP: error or timeout\n");
+ log->log("TCP", Log::DEBUG, "TCP: error or timeout");
return 0; // error, or timeout
}
}
bytesRead += thisRead;
- printf("Bytes read now: %u\n", bytesRead);
+// log->log("TCP", Log::DEBUG, "Bytes read now: %u", bytesRead);
if (bytesRead == totalBytes)
{
return 1;
if (++readTries == 100)
{
cleanup();
- printf("too many reads\n");
+ log->log("TCP", Log::DEBUG, "too many reads");
return 0;
}
}
if (success < 1)
{
cleanup();
- printf("TCP: error or timeout\n");
+ log->log("TCP", Log::DEBUG, "TCP: error or timeout");
return 0; // error, or timeout
}
// in non-blocking mode if read is called with no data available, it returns -1
// and sets errno to EGAGAIN. but we use select so it wouldn't do that anyway.
cleanup();
- printf("Detected connection closed\n");
+ log->log("TCP", Log::DEBUG, "Detected connection closed");
return 0;
}
bytesWritten += thisWrite;
- printf("Bytes written now: %u\n", bytesWritten);
+// log->log("TCP", Log::DEBUG, "Bytes written now: %u", bytesWritten);
if (bytesWritten == count)
{
return 1;
if (++writeTries == 100)
{
cleanup();
- printf("too many writes\n");
+ log->log("TCP", Log::DEBUG, "too many writes");
return 0;
}
}
#include <fcntl.h>
#include <ctype.h>
+#include "log.h"
+
typedef unsigned char UCHAR;
typedef unsigned short USHORT;
static UCHAR dcc(UCHAR c);
private:
+ Log* log;
int sock;
int connected;
int readTimeoutEnabled;
cMediamvpTransceiver::cMediamvpTransceiver(const cChannel *Channel, int Priority, int Socket, cDevice *Device) :
cReceiver(Channel->Ca(), Priority, Channel->Vpid(),
Channel->Apids(), Channel->Dpids(), Channel->Spids()) {
-#endif
- m_Active = false;
+#endif
+ m_Active = false;
m_Socket = Socket;
m_Remux = NULL;
m_Device = Device;
+//cjt
+ log = Log::getInstance();
+
m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true);
// m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 20, true);
m_Remux = new cTS2PSRemux(Channel->Vpid(), Channel->Apid(0), 0, 0, 0, 0);
}
#endif
- printf("Created transceiver at %p, remux @%p ringbuffer %p\n",this,m_Remux,m_RingBuffer);
+ log->log("Transciever", Log::DEBUG, "Created transceiver at %p, remux @%p ringbuffer %p",this,m_Remux,m_RingBuffer);
/* Suggested by Peter Wagner to assist single DVB card systems */
#ifdef SINGLE_DEVICE
cMediamvpTransceiver::~cMediamvpTransceiver(void)
{
- printf("Deleting transceiver at %p, remux @%p ringbuffer %p\n",this,m_Remux,m_RingBuffer);
+ log->log("Transciever", Log::DEBUG, "Deleting transceiver at %p, remux @%p ringbuffer %p",this,m_Remux,m_RingBuffer);
Detach();
if (m_Remux)
if (p != Length) {
++errcnt;
#if VDRVERSNUM < 10300
- if (showerr) {
+ if (showerr) {
if (firsterr == 0)
firsterr = time_ms();
else if (firsterr + BUFOVERTIME > time_ms() && errcnt > BUFOVERCOUNT) {
else
firsterr = time_ms();
#else
- if (showerr) {
+ if (showerr) {
if (firsterr == 0) {
firsterr = 1;
- lastTime.Set();
- }
+ lastTime.Set();
+ }
else if (lastTime.Elapsed() > BUFOVERTIME && errcnt > BUFOVERCOUNT) {
esyslog("ERROR: too many buffer overflows, logging stopped");
showerr = false;
int max = 0;
- printf("Mediamvp: Transceiver thread started (pid=%d)", getpid());
+ log->log("Transciever", Log::DEBUG, "Mediamvp: Transceiver thread started (pid=%d)", getpid());
m_Active = true;
}
- printf("Mediamvp: Transceiver thread ended");
+ log->log("Transciever", Log::DEBUG, "Mediamvp: Transceiver thread ended");
}
unsigned long cMediamvpTransceiver::getBlock(unsigned char* buffer, unsigned long amount)
/*
Edited for VOMP by Chris Tallon
Edits Copyright 2004-2005 Chris Tallon
+
+ This class will be replaced soon.
*/
/*
#include <pthread.h>
#include "ringbuffer.h"
+#include "log.h"
class cMediamvpTransceiver: public cReceiver, public cThread {
// friend class cMediamvpVdrURL;
bool m_Active;
#if VDRVERSNUM >= 10300
- cTimeMs lastTime;
+ cTimeMs lastTime;
#endif
// CJT
Ringbuffer rb;
pthread_mutex_t ringLock;
+ Log* log;
protected:
if (running) return 1;
running = 1;
if (pthread_create(&runThread, NULL, (void*(*)(void*))UDPReplierStartThread, (void *)this) == -1) return 0;
- printf("UDPReplier run success\n");
+ Log::getInstance()->log("UDP", Log::DEBUG, "UDP replier started");
return 1;
}
#include <pthread.h>
#include <signal.h>
+#include "log.h"
#include "dsock.h"
class UDPReplier
bool cPluginVompserver::Initialize(void)
{
// Initialize any background activities the plugin shall perform.
- printf("VOMP Plugin init\n");
return true;
}
bool cPluginVompserver::Start(void)
{
// Start any background activities the plugin shall perform.
- printf("VOMP Plugin start\n");
-
int success = mvpserver.run();
if (success) return true;
else return false;