]> git.tdb.fi Git - libs/core.git/commitdiff
Win32 tweaks
authorNiko Liikanen <cloud@neo-midgar.com>
Thu, 24 Aug 2006 16:03:09 +0000 (16:03 +0000)
committerNiko Liikanen <cloud@neo-midgar.com>
Thu, 24 Aug 2006 16:03:09 +0000 (16:03 +0000)
Makefile
source/application.cpp
source/application.h
source/event.cpp
source/pollable.cpp
source/pollable.h
source/poller.cpp
source/poller.h
source/thread.cpp
source/thread.h
source/win32poll.h [new file with mode: 0644]

index b88954c35ffe0769c2682af2ef2042385b90252c..83df8405397b6156175ccafdf471c1670690c955 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,6 @@
+LIBRARY                = framework
+LIBFILE                = libmspframework
+
 TMP            = $(HOME)/nightwatch/tmp
 TGT            = $(HOME)/nightwatch
 
 TMP            = $(HOME)/nightwatch/tmp
 TGT            = $(HOME)/nightwatch
 
@@ -5,14 +8,19 @@ CXX           = g++
 CC             = gcc
 AR             = ar
 CP             = cp
 CC             = gcc
 AR             = ar
 CP             = cp
+
 INCLUDE                = -Isource -I$(TMP)/include
 LIB            = -L$(TMP)
 DEBUG          = 
 INCLUDE                = -Isource -I$(TMP)/include
 LIB            = -L$(TMP)
 DEBUG          = 
-CFLAGS         = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0` `sdl-config --cflags`
+CFLAGS         = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0`
 CXXFLAGS       = $(CFLAGS)
 CXXFLAGS       = $(CFLAGS)
+LIBLDFLAGS     = -lpthreadGC2 -lsigc-2.0
+MAKEFLAGS      += -s --no-print-directory
+
+PIC            = -fPIC
+SHARED         = .so
+STATIC         = .a
 
 
-LIBRARY                = framework
-LIBFILE                = libmspframework
 SRC            = source
 LIBOBJS                = $(addprefix $(TMP)/, $(addsuffix .o, $(notdir $(basename $(wildcard $(SRC)/*.cpp)))))
 
 SRC            = source
 LIBOBJS                = $(addprefix $(TMP)/, $(addsuffix .o, $(notdir $(basename $(wildcard $(SRC)/*.cpp)))))
 
@@ -20,19 +28,19 @@ pkgincludedir       = include/msp/$(LIBRARY)
 libdir         = lib
 
 .PHONY: all
 libdir         = lib
 
 .PHONY: all
-all: $(TMP) $(TMP)/$(LIBFILE).so $(TMP)/$(LIBFILE).a tmpheaders
+all: $(TMP) $(TMP)/$(LIBFILE)$(SHARED) $(TMP)/$(LIBFILE)$(STATIC) tmpheaders
 
 # Create temp directory
 $(TMP):
        mkdir -p $@
 
 # Dynamic library
 
 # Create temp directory
 $(TMP):
        mkdir -p $@
 
 # Dynamic library
-$(TMP)/$(LIBFILE).so: $(LIBOBJS)
+$(TMP)/$(LIBFILE)$(SHARED): $(LIBOBJS)
        echo "Compiling $(notdir $@)"
        echo "Compiling $(notdir $@)"
-       $(CXX) $^ -shared -o $@ $(LIB) $(LIBRARYLIBS)
+       $(CXX) $^ -shared -o $@ $(LIB) $(LIBLDFLAGS)
 
 # Static library
 
 # Static library
-$(TMP)/$(LIBFILE).a: $(LIBOBJS)
+$(TMP)/$(LIBFILE)$(STATIC): $(LIBOBJS)
        echo "Compiling $(notdir $@)"
        $(AR) rcs $@ $^
 
        echo "Compiling $(notdir $@)"
        $(AR) rcs $@ $^
 
@@ -47,7 +55,7 @@ $(TMP)/$(pkgincludedir):
 # Library object file
 $(TMP)/%.o: $(SRC)/%.cpp $(wildcard $(SRC)/*.h)
        echo "Compiling $(LIBRARY)/$(notdir $(basename $@))"
 # Library object file
 $(TMP)/%.o: $(SRC)/%.cpp $(wildcard $(SRC)/*.h)
        echo "Compiling $(LIBRARY)/$(notdir $(basename $@))"
-       $(CXX) -fPIC $(CXXFLAGS) -c $< -o $@
+       $(CXX) $(PIC) $(CXXFLAGS) -c $< -o $@
 
 # Installs
 .PHONY: install
 
 # Installs
 .PHONY: install
index 765b0670d3ecee5ccaad9228b02306769022e0d7..22c8d2688310685fb2aaeb4e30857256bcc7c062 100644 (file)
@@ -114,8 +114,12 @@ int Application::main()
                                poller_->poll(-1);
                        else
                        {
                                poller_->poll(-1);
                        else
                        {
+#ifdef WIN32
+                               Sleep(1);
+#else
                                timespec ts={1000,0};
                                nanosleep(&ts, 0);
                                timespec ts={1000,0};
                                nanosleep(&ts, 0);
+#endif
                        }
                        if(tick_mode_!=NONE)
                                tick();
                        }
                        if(tick_mode_!=NONE)
                                tick();
index 4296b6f1b6811db6cf9354516297e3872c5973bb..b2502edd83501094060450dae399d234b4444d51 100644 (file)
@@ -6,6 +6,10 @@ Distributed under the LGPL
 #ifndef MSP_FRAMEWORK_APPLICATION_H_
 #define MSP_FRAMEWORK_APPLICATION_H_
 
 #ifndef MSP_FRAMEWORK_APPLICATION_H_
 #define MSP_FRAMEWORK_APPLICATION_H_
 
+#ifdef WIN32
+#include "win32signum.h"
+#endif
+
 #include <pthread.h>
 #include "event.h"
 #include "poller.h"
 #include <pthread.h>
 #include "event.h"
 #include "poller.h"
index b314fca1730543c0697bfd4abd6f11e8572e1a10..01b8542a6225c2d0fb7cd703e4bb32d93283ce32 100644 (file)
@@ -3,6 +3,11 @@ This file is part of libmspframework
 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
+#ifdef WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+
 #include "application.h"
 #include "event.h"
 
 #include "application.h"
 #include "event.h"
 
@@ -42,17 +47,29 @@ void EventManager::Event::trigger()
 
 EventManager::Pipe::Pipe()
 {
 
 EventManager::Pipe::Pipe()
 {
+#ifdef WIN32
+       _pipe(fd, 1024, _O_BINARY);
+#else
        ::pipe(fd);
        ::pipe(fd);
+#endif
 }
 
 int EventManager::Pipe::write(char *buf, unsigned len)
 {
 }
 
 int EventManager::Pipe::write(char *buf, unsigned len)
 {
+#ifdef WIN32
+       return _write(fd[1], buf, len);
+#else
        return ::write(fd[1], buf, len);
        return ::write(fd[1], buf, len);
+#endif
 }
 
 int EventManager::Pipe::read(char *buf, unsigned len)
 {
 }
 
 int EventManager::Pipe::read(char *buf, unsigned len)
 {
+#ifdef WIN32
+       return _read(fd[0], buf, len);
+#else
        return ::read(fd[0], buf, len);
        return ::read(fd[0], buf, len);
+#endif
 }
 
 } // namespace Msp
 }
 
 } // namespace Msp
index 805521d7e2383a77025547707c510a3278a81844..4b0cb1c7bb3804e3aeef109a27405ae0ceac57c8 100644 (file)
@@ -3,18 +3,28 @@ This file is part of libmspframework
 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
+#ifdef WIN32
+#include <winsock2.h>
+#include "win32poll.h"
+#else
 #include <poll.h>
 #include <poll.h>
+#endif
 #include "pollable.h"
 
 namespace Msp {
 
 short Pollable::poll(short events, int timeout)
 {
 #include "pollable.h"
 
 namespace Msp {
 
 short Pollable::poll(short events, int timeout)
 {
+#ifdef WIN32
+       return 0;
+#else
        pollfd pfd={get_fd(), events, 0};
        pollfd pfd={get_fd(), events, 0};
+       int result=select(&pfd, 1, timeout);
        int result=::poll(&pfd, 1, timeout);
        if(result<=0)
                return result;
        return pfd.revents;
        int result=::poll(&pfd, 1, timeout);
        if(result<=0)
                return result;
        return pfd.revents;
+#endif
 }
 
 }
 }
 
 }
index 46cfb2347629689987d165d49a3642d81933fbe6..f676d55f2224f4bf62c6a85235018a69ed3aa5d2 100644 (file)
@@ -6,6 +6,10 @@ Distributed under the LGPL
 #ifndef MSP_FRAMEWORK_POLLABLE_H_
 #define MSP_FRAMEWORK_POLLABLE_H_
 
 #ifndef MSP_FRAMEWORK_POLLABLE_H_
 #define MSP_FRAMEWORK_POLLABLE_H_
 
+#ifdef WIN32
+#include "win32poll.h"
+#endif
+
 #include <sigc++/sigc++.h>
 
 namespace Msp {
 #include <sigc++/sigc++.h>
 
 namespace Msp {
index 09193661a3c8f0ab82ac159e95b144b0fd78d227..4a623d4e1c9bd67672a04830df075281a3bf7e96 100644 (file)
@@ -27,6 +27,9 @@ Poller::Slot &Poller::add_pollable(Pollable *obj, short events)
 
 int Poller::poll(int timeout)
 {
 
 int Poller::poll(int timeout)
 {
+#ifdef WIN32
+       return 0;
+#else
        slots_mutex.lock();
        for(list<Slot *>::iterator i=slots.begin(); i!=slots.end();)
        {
        slots_mutex.lock();
        for(list<Slot *>::iterator i=slots.begin(); i!=slots.end();)
        {
@@ -71,6 +74,7 @@ int Poller::poll(int timeout)
        pfd_mutex.unlock();
        
        return result;
        pfd_mutex.unlock();
        
        return result;
+#endif
 }
 
 void Poller::rebuild_pfd()
 }
 
 void Poller::rebuild_pfd()
index b299b75334efb64d2661f9fbb286e65ee29a6bf7..dcd36587054b2d10599918adc84a0c6ef10f880c 100644 (file)
@@ -6,7 +6,11 @@ Distributed under the LGPL
 #ifndef MSP_FRAMEWORK_POLLER_H_
 #define MSP_FRAMEWORK_POLLER_H_
 
 #ifndef MSP_FRAMEWORK_POLLER_H_
 #define MSP_FRAMEWORK_POLLER_H_
 
+#ifdef WIN32
+#include "win32poll.h"
+#else
 #include <sys/poll.h>
 #include <sys/poll.h>
+#endif
 #include <vector>
 #include <sigc++/sigc++.h>
 #include "mutex.h"
 #include <vector>
 #include <sigc++/sigc++.h>
 #include "mutex.h"
index 6bc744422c55555bc11e8751618101db1d8a6d29..ba0c479770b4c7cbcee4c975e19180565dad4ea5 100644 (file)
@@ -21,7 +21,7 @@ void *Thread::join()
 
 Thread::~Thread()
 {
 
 Thread::~Thread()
 {
-       if(valid)
+       if(valid_)
                kill(SIGKILL);
 }
 
                kill(SIGKILL);
 }
 
index b9910ff2135cfaab67c30cbfe71d21b23f741516..51ca0ef3395c2abe80d182a6cef056429d655e75 100644 (file)
@@ -6,6 +6,10 @@ Distributed under the LGPL
 #ifndef MSP_FRAMEWORK_THREAD_H_
 #define MSP_FRAMEWORK_THREAD_H_
 
 #ifndef MSP_FRAMEWORK_THREAD_H_
 #define MSP_FRAMEWORK_THREAD_H_
 
+#ifdef WIN32
+#include "win32signum.h"
+#endif
+
 #include <pthread.h>
 
 namespace Msp {
 #include <pthread.h>
 
 namespace Msp {
diff --git a/source/win32poll.h b/source/win32poll.h
new file mode 100644 (file)
index 0000000..f39d53e
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+This file is part of libmspframework
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#ifndef MSP_FRAMEWORK_WIN32POLL_H_
+#define MSP_FRAMEWORK_WIN32POLL_H_
+
+#ifdef WIN32
+// From Linux sys/poll.h
+struct pollfd
+{
+       int fd;                 /* File descriptor to poll.  */
+       short int events;       /* Types of events poller cares about.  */
+       short int revents;      /* Types of events that actually occurred.  */
+};
+
+#ifndef POLLIN
+// From Linux pth.h
+#define POLLIN         0x0001  /* any readable data available   */
+#endif
+
+#ifndef POLLNVAL
+// From Linux pth.h
+#define POLLNVAL       0x0020  /* requested events "invalid"    */
+#endif
+
+#endif // Win32
+#endif