tv.tv_usec = 0;
int allowed = 1;
- setsockopt(socketnum, SOL_SOCKET, SO_BROADCAST, &allowed, sizeof(allowed));
+ setsockopt(socketnum, SOL_SOCKET, SO_BROADCAST, (char*)&allowed, sizeof(allowed));
}
DatagramSocket::~DatagramSocket()
#ifndef DSOCK_H
#define DSOCK_H
+#ifndef WIN32
+
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
+#else
+#include <winsock2.h>
+#include <Ws2tcpip.h>
+#endif
+
#include <sys/types.h>
+
+#ifndef WIN32
#include <sys/time.h>
+#else
+#include <sys/timeb.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#ifdef WIN32
+#include <winsock2.h>
#include <shlwapi.h>
#endif
char buffer[151];
int spaceLeft = 150;
+#ifndef _MSC_VER
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm* tms = localtime(&tv.tv_sec);
+#else
+ struct _timeb tb;
+ _ftime(&tb);
+ struct tm* tms = localtime(&tb.time);
+#endif
+
spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tms);
spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
#ifndef WIN32
#include <sys/time.h>
#else
+ #include <winsock2.h>
#include <sys/timeb.h>
#endif
#include "videomvp.h"
#endif
+#ifndef WIN32
void sighandler(int signalReceived);
+#endif
+
void shutdown(int code);
// Global variables --------------------------------------------------------------------------------------------------
Video* video;
Audio* audio;
+// Linux MVP main function and sighandler
+#ifndef WIN32
int main(int argc, char** argv)
{
if ((argc > 1) && (!strcmp(argv[1], "-d"))) debugEnabled = 1;
logger = new Log();
timers = new Timers();
vdr = new VDR();
-#ifdef WIN32
- mtd = new MtdWin();
- remote = new RemoteWin();
- led = new LedWin();
- osd = new OsdWin();
- audio = new AudioWin();
- video = new VideoWin();
-#else
mtd = new MtdMVP();
remote = new RemoteMVP();
led = new LedMVP();
osd = new OsdMVP();
audio = new AudioMVP();
video = new VideoMVP();
-#endif
viewman = new ViewMan();
command = new Command();
shutdown(1);
}
-#ifdef WIN32
- success = led->init();
-#else
success = led->init(((RemoteMVP*)remote)->getDevice());
-#endif
if (success)
{
logger->log("Core", Log::INFO, "LED module initialised");
// -------------------------------------------------------------------------------------------------------------------
+void sighandler(int signalReceived)
+{
+ logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
+
+ switch (signalReceived)
+ {
+ case SIGINT:
+ {
+ logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
+ command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
+ break;
+ }
+ case SIGTERM:
+ {
+ logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
+ command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
+ break;
+ }
+ case SIGUSR1:
+ {
+ command->sig1();
+ break;
+ }
+/*
+ case SIGUSR1:
+ {
+ logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
+ logger->upLogLevel();
+ break;
+ }
+ case SIGUSR2:
+ {
+ logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
+ logger->downLogLevel();
+ break;
+ }
+*/
+ case SIGURG:
+ {
+ logger->log("Core", Log::DEBUG, "SIGURG caught");
+ break;
+ }
+ }
+}
+#endif
+
+// -------------------------------------------------------------------------------------------------------------------
+
void shutdown(int code)
{
if (viewman)
// -------------------------------------------------------------------------------------------------------------------
-void sighandler(int signalReceived)
-{
- logger->log("Core", Log::NOTICE, "Signal %i received", signalReceived);
-
- switch (signalReceived)
- {
- case SIGINT:
- {
- logger->log("Core", Log::NOTICE, "Interrupt signal, shutting down...");
- command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
- break;
- }
- case SIGTERM:
- {
- logger->log("Core", Log::NOTICE, "Term signal, shutting down...");
- command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
- break;
- }
- case SIGUSR1:
- {
- command->sig1();
- break;
- }
-/*
- case SIGUSR1:
- {
- logger->log("Core", Log::DEBUG, "SIGUSR1 caught");
- logger->upLogLevel();
- break;
- }
- case SIGUSR2:
- {
- logger->log("Core", Log::DEBUG, "SIGUSR2 caught");
- logger->downLogLevel();
- break;
- }
-*/
- case SIGURG:
- {
- logger->log("Core", Log::DEBUG, "SIGURG caught");
- break;
- }
- }
-}
-
-// -------------------------------------------------------------------------------------------------------------------
-
ULLONG ntohll(ULLONG a)
{
return htonll(a);
int tail = bufferTail;
int mark = bufferMark;
int written;
-
+#ifndef WIN32
if (mark == -1 && tail > head) mark = bufferSize;
if (mark >= 0)
ret += written;
bufferTail = tail + written;
return ret;
+ #else
+ return 0; //to do!
+ #endif //Again this have to betransformed into abstract base class and derived class
+
}
#define STREAM_H
#include <stdlib.h>
+#ifndef WIN32
#include <unistd.h>
+#endif
#include <memory.h>
#include "defines.h"
void TCP::getMAC(char* dest)
{
+#ifndef WIN32
struct ifreq ifr;
strcpy(ifr.ifr_name, "eth0");
ioctl(sock, SIOCGIFHWADDR, &ifr);
memcpy(dest, ifr.ifr_hwaddr.sa_data, 6);
+#else
+ //TODO: Get MAC Address for windows
+ memcpy(dest, "ABCDEF", 6);
+#endif
}
int TCP::connectTo(char* host, unsigned short port)
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(port);
+#ifndef WIN32
if (!inet_aton(host, &dest_addr.sin_addr))
+#else
+ dest_addr.sin_addr.s_addr = inet_addr(host);
+ if (dest_addr.sin_addr.s_addr == INADDR_NONE)
+#endif
{
- close(sock);
+ CLOSESOCKET(sock);
return 0;
}
memset(&(dest_addr.sin_zero), '\0', 8);
// set non blocking
+#ifndef WIN32
int oldflags = fcntl (sock, F_GETFL, 0);
oldflags |= O_NONBLOCK;
fcntl(sock, F_SETFL, oldflags);
+#else
+ unsigned long flag=1;
+ ioctlsocket(sock,FIONBIO,&flag);
+
+#endif
// setReceiveWindow(2048);
// first check errno for EINPROGRESS, otherwise it's a fail
// this doesn't work?
+#ifndef WIN32
if (errno != EINPROGRESS)
+#else
+ int wsalasterr = WSAGetLastError();
+ if ((wsalasterr != WSAEWOULDBLOCK) && (wsalasterr != WSAEINPROGRESS))
+#endif
{
- close(sock);
+ CLOSESOCKET(sock);
return 0;
}
int soError;
socklen_t soErrorSize = sizeof(soError);
- int gso = getsockopt(sock, SOL_SOCKET, SO_ERROR, &soError, &soErrorSize);
+ int gso = getsockopt(sock, SOL_SOCKET, SO_ERROR,(char*) &soError, &soErrorSize);
if ((gso == 0) && (soError == 0))
{
void TCP::setReceiveWindow(size_t rxBufferSize)
{
// Set receive window
- int r = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &rxBufferSize, sizeof(size_t));
+ int r = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char*)&rxBufferSize, sizeof(size_t));
Log::getInstance()->log("TCP", Log::DEBUG, "Set receive window to %i, success(=0): %i", rxBufferSize, r);
}
{
do
{
+#ifndef WIN32
temp_write = this_write = write(sock, buf, count - bytes_sent);
// Log::getInstance()->log("TCP", Log::DEBUG, "TCP has written %i bytes", temp_write);
} while ( (this_write < 0) && (errno == EINTR) );
-
-
+#else
+ temp_write = this_write = send(sock,(char*) buf, count- bytes_sent,0);
+ } while ( (this_write == SOCKET_ERROR) && (WSAGetLastError() == WSAEINTR) );
+#endif
if (this_write <= 0)
{
return(this_write);
{
Log::getInstance()->log("TCP", Log::ERR, "readData failed");
free(buffer);
- close(sock);
+ CLOSESOCKET(sock);
connected = 0;
return NULL;
}
Log::getInstance()->log("TCP", Log::ERR, "Error or timeout");
return 0; // error, or timeout
}
-
+#ifndef WIN32
thisRead = read(sock, &buffer[bytesRead], totalBytes - bytesRead);
+#else
+ thisRead = recv(sock,(char*) &buffer[bytesRead],totalBytes - bytesRead, 0);
+#endif
// printf("read %i\n", thisRead);
if (!thisRead)
{
return 0;
}
-int ThreadP::threadStart()
+int ThreadWin::threadStart()
{
threadCond = CreateEvent(NULL,FALSE,FALSE,NULL);
if (threadCond == NULL) return 0;
- threadCondMutex = CreateMutex(NULL,TRUE,NULL);
+ threadCondMutex = CreateMutex(NULL,FALSE,NULL);
if (threadCondMutex == NULL)
{
CloseHandle(threadCond);
return 1;
}
-void ThreadP::threadStop()
+void ThreadWin::threadStop()
{
threadActive = 0;
// Signal thread here in case it's waiting
this->threadPostStopCleanup();
}
-void ThreadP::threadCancel()
+void ThreadWin::threadCancel()
{
threadActive = 0;
TerminateThread(pthread, 0);
this->threadPostStopCleanup();
}
-void ThreadP::threadCheckExit()
+void ThreadWin::threadCheckExit()
{
if (!threadActive) ExitThread(NULL);
}
-void ThreadP::threadLock()
+void ThreadWin::threadLock()
{
WaitForSingleObject(threadCondMutex, INFINITE);
}
-void ThreadP::threadUnlock()
+void ThreadWin::threadUnlock()
{
ReleaseMutex(threadCondMutex);
}
-void ThreadP::threadSignal()
+void ThreadWin::threadSignal()
{
WaitForSingleObject(threadCondMutex, INFINITE);
- SetEvent(threadCond);
+ PulseEvent(threadCond);
ReleaseMutex(threadCondMutex);
}
-void ThreadP::threadSignalNoLock()
+void ThreadWin::threadSignalNoLock()
{
- SetEvent(threadCond);
+ PulseEvent(threadCond);
}
-void ThreadP::threadWaitForSignal()
+void ThreadWin::threadWaitForSignal()
{
WaitForSingleObject(threadCond,INFINITE);
}
-void ThreadP::threadWaitForSignalTimed(struct timespec* ts)
+void ThreadWin::threadWaitForSignalTimed(struct timespec* ts)
{
HANDLE handles[2] ={threadCond, NULL};
LARGE_INTEGER duration;
duration.QuadPart=ts->tv_sec*1000*1000*10+ts->tv_nsec/100;
handles[1]=CreateWaitableTimer(NULL,TRUE,NULL);
- /* SetWaitableTimer(handles[1], &duration, 0, NULL, NULL, 0);
- WaitForMultipleObject(2,handles,INFINITE);*/
+ SetWaitableTimer(handles[1], &duration, 0, NULL, NULL, 0);
+ WaitForMultipleObjects(2,handles,FALSE,INFINITE);
CloseHandle(handles[1]);
}
-void ThreadP::threadSetKillable()
+void ThreadWin::threadSetKillable()
{
//WIN32:Ignore or use a separate Event Object to simulate this
}
int Timers::setTimerD(TimerReceiver* client, int clientReference, long int requestedSecs, long int requestedNSecs)\r
{\r
struct timespec currentTime;\r
+\r
+#ifndef WIN32\r
clock_gettime(CLOCK_REALTIME, ¤tTime);\r
+#else\r
+ SYSTEMTIME systime;\r
+ __int64 filetime;\r
+ __int64 test;\r
+ GetSystemTime(&systime);\r
+ SystemTimeToFileTime(&systime,(FILETIME*)&filetime);\r
+ currentTime.tv_sec=filetime/(10*1000*1000);\r
+ currentTime.tv_nsec=(filetime%(10*1000*1000))*100;\r
+#endif\r
\r
long int requestedTime;\r
long int requestedTimeNSEC;\r
threadUnlock();\r
//logger->log("Timers", Log::DEBUG, "un-LOCKED -TIMERS- MUTEX (3)");\r
//printf("\n\n\n WOOOOO \n\n\n The anti deadlock code is working!!! \n\n\n");\r
- usleep(10000); // 10ms - too long?\r
+ MILLISLEEP(10); // 10ms - too long?\r
//logger->log("Timers", Log::DEBUG, "Waiting for LOCK -TIMERS- MUTEX 7");\r
threadLock();\r
//logger->log("Timers", Log::DEBUG, "LOCKED -TIMERS- MUTEX 7");\r
#define TIMERS_H
#include <stdio.h>
+#ifndef WIN32
#include <pthread.h>
+#endif
#include <list>
#include "defines.h"