VDR* VDR::instance = NULL;
+#ifndef WIN32
+#define MUTEX_LOCK(mutex) pthread_mutex_lock(mutex)
+#define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(mutex)
+#else
+#define MUTEX_LOCK(mutex) WaitForSingleObject(mutex, INFINITE )
+#define MUTEX_UNLOCK(mutex) ReleaseMutex(mutex)
+#endif
+
+
VDR::VDR()
{
if (instance) return;
initted = 0;
findingServer = 0;
tcp = NULL;
+#ifndef WIN32
pthread_mutex_init(&mutex, NULL);
+#else
+ mutex=CreateMutex(NULL,TRUE,NULL);
+#endif
packetLength = 0;
packetPos = 0;
packet = NULL;
VDR::~VDR()
{
+#ifdef WIN32
+ CloseHandle(mutex);
+#endif
instance = NULL;
if (initted) shutdown();
}
tcp->getMAC((char*)&buffer[8]);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
+ MUTEX_LOCK(&mutex);
+ if (!connected)
+ {
+ MUTEX_UNLOCK(&mutex);
+ return 0;
+ }
int a = tcp->sendPacket(buffer, 14);
if (a != 14)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
+ // Set the time and zone on the MVP
+#ifndef WIN32
struct timespec currentTime;
currentTime.tv_sec = vdrTime;
currentTime.tv_nsec = 0;
setenv("TZ", newTZ, 1);
logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
+#endif
return 1;
}
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected)
+ {
+ MUTEX_UNLOCK(&mutex);
+ return 0;
+ }
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
}
freePacket();
- pthread_mutex_unlock(&mutex);
-
+ MUTEX_UNLOCK(&mutex);
// Sort the directory order
sort(recDir->dirList.begin(), recDir->dirList.end(), DirectorySorter());
int VDR::deleteRecording(char* fileName)
{
unsigned long totalLength = 8 + strlen(fileName) + 1;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_DELETERECORDING);
strcpy((char*)&buffer[8], fileName);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
int toReturn = (int)extractULONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
char* VDR::getRecordingSummary(char* fileName)
{
unsigned long totalLength = 8 + strlen(fileName) + 1;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETSUMMARY);
strcpy((char*)&buffer[8], fileName);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
char* toReturn = extractString();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
}
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return chanList;
}
*(unsigned long*)&buffer[4] = htonl(VDR_STREAMCHANNEL);
*(unsigned long*)&buffer[8] = htonl(number);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 12);
if (a != 12)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
int toReturn = (int)extractULONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
int toReturn = (int)extractULONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
*(ULLONG*)&buffer[8] = htonll(position);
*(unsigned long*)&buffer[16] = htonl(maxAmount);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 20);
if (a != 20)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
{
Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
packet = NULL;
packetLength = 0;
packetPos = 0;
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
+
return toReturn;
}
ULLONG VDR::streamRecording(Recording* rec)
{
unsigned long totalLength = 8 + strlen(rec->fileName) + 1;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING);
strcpy((char*)&buffer[8], rec->fileName);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
ULLONG recordingLength = extractULLONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu", recordingLength);
ULLONG VDR::rescanRecording()
{
unsigned long totalLength = 8;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
ULLONG recordingLength = extractULLONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu", recordingLength);
ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
{
unsigned long totalLength = 12;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_POSFROMFRAME);
*(unsigned long*)&buffer[8] = htonl(frameNumber);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
ULLONG position = extractULLONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
*(unsigned long*)&buffer[12] = htonl(start);
*(unsigned long*)&buffer[16] = htonl(duration);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 20);
if (a != 20)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (serverError())
{
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
-
EventList* eventList = new EventList();
while (packetPos < packetLength)
}
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
int VDR::configSave(char* section, char* key, const char* value)
{
ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_CONFIGSAVE);
position += strlen(key) + 1;
strcpy((char*)&buffer[position], value);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete[] buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
int toReturn = (int)extractULONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
char* VDR::configLoad(char* section, char* key)
{
ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_CONFIGLOAD);
position += strlen(section) + 1;
strcpy((char*)&buffer[position], key);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete[] buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
char* toReturn = extractString();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return NULL;
}
}
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
// Sort the list
ULONG VDR::setEventTimer(char* timerString)
{
unsigned long totalLength = 8 + strlen(timerString) + 1;
- UCHAR buffer[totalLength];
+ UCHAR* buffer = new UCHAR[totalLength];
*(unsigned long*)&buffer[0] = htonl(totalLength - 4);
*(unsigned long*)&buffer[4] = htonl(VDR_SETTIMER);
strcpy((char*)&buffer[8], timerString);
- pthread_mutex_lock(&mutex);
- if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+ MUTEX_LOCK(&mutex);
+ if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
unsigned int a = tcp->sendPacket(buffer, totalLength);
+ delete []buffer;
+
if (a != totalLength)
{
disconnect();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
if (!getPacket())
{
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return 0;
}
ULONG toReturn = extractULONG();
freePacket();
- pthread_mutex_unlock(&mutex);
+ MUTEX_UNLOCK(&mutex);
return toReturn;
}