Adopted sources for build with Microsoft Visual Studio 2013
authorStefan Laner <laner@itestra.de>
Mon, 21 Oct 2013 13:41:50 +0000 (15:41 +0200)
committerStefan Laner <laner@itestra.de>
Mon, 21 Oct 2013 13:41:50 +0000 (15:41 +0200)
src/CommonAPI/DBus/DBusMainLoopContext.cpp [changed mode: 0644->0755]
src/CommonAPI/DBus/DBusMainLoopContext.h [changed mode: 0644->0755]
src/CommonAPI/DBus/DBusRuntime.cpp [changed mode: 0644->0755]
src/CommonAPI/DBus/DBusUtils.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 9b9c57c..e4df446
@@ -9,7 +9,11 @@
 #include "DBusMainLoopContext.h"
 #include "DBusConnection.h"
 
+#ifdef WIN32
+#include <CommonAPI/pollStructures.h>
+#else
 #include <poll.h>
+#endif
 #include <chrono>
 
 
@@ -73,7 +77,7 @@ void DBusWatch::stopWatching() {
     lockedContext->deregisterWatch(this);
 }
 
-const pollfd& DBusWatch::getAssociatedFileDescriptor() {
+const COMMONAPI_POLLFD& DBusWatch::getAssociatedFileDescriptor() {
     return pollFileDescriptor_;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 8558527..52f35b6
 
 #include <list>
 #include <memory>
-#include <poll.h>
+#include <CommonAPI/MainLoopContext.h>
 
 #include <dbus/dbus.h>
 
-#include <CommonAPI/MainLoopContext.h>
 
 
 namespace CommonAPI {
@@ -47,7 +46,7 @@ class DBusWatch: public Watch {
 
     void dispatch(unsigned int eventFlags);
 
-    const pollfd& getAssociatedFileDescriptor();
+       const COMMONAPI_POLLFD& getAssociatedFileDescriptor();
 
     const std::vector<DispatchSource*>& getDependentDispatchSources();
     void addDependentDispatchSource(DispatchSource* dispatchSource);
@@ -56,7 +55,7 @@ class DBusWatch: public Watch {
     bool isReady();
 
     ::DBusWatch* libdbusWatch_;
-    pollfd pollFileDescriptor_;
+       COMMONAPI_POLLFD pollFileDescriptor_;
     std::vector<DispatchSource*> dependentDispatchSources_;
 
     std::weak_ptr<MainLoopContext> mainLoopContext_;
old mode 100644 (file)
new mode 100755 (executable)
index 6be703c..9f21b42
@@ -11,8 +11,16 @@ namespace DBus {
 
 const MiddlewareInfo DBusRuntime::middlewareInfo_("DBus", &DBusRuntime::getInstance);
 
-__attribute__((constructor)) void registerDBusMiddleware(void) {
-    Runtime::registerRuntimeLoader("DBus", &DBusRuntime::getInstance);
+#ifdef WIN32
+#pragma section(".CRT$XCU",read)
+void __cdecl registerDBusMiddleware(void);
+__declspec(allocate(".CRT$XCU")) void(__cdecl*registerDBusMiddleware_)(void) = registerDBusMiddleware;
+void __cdecl
+#else
+__attribute__((constructor)) void
+#endif
+ registerDBusMiddleware(void) {
+       Runtime::registerRuntimeLoader("DBus", &DBusRuntime::getInstance);
 }
 
 std::shared_ptr<Runtime> DBusRuntime::getInstance() {
@@ -28,12 +36,11 @@ std::shared_ptr<Factory> DBusRuntime::createFactory(std::shared_ptr<MainLoopCont
     return factory;
 }
 
+} // namespace DBus
+} // namespace CommonAPI
 
 extern "C" {
 
-CommonAPI::MiddlewareInfo middlewareInfo = CommonAPI::DBus::DBusRuntime::middlewareInfo_;
-
-}
+       CommonAPI::MiddlewareInfo middlewareInfo = CommonAPI::DBus::DBusRuntime::middlewareInfo_;
 
-} // namespace DBus
-} // namespace CommonAPI
+}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 4c4c078..f31faaa
 #include <string>
 #include <sstream>
 #include <vector>
-#include <unistd.h>
 #include <future>
 
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN // this prevents windows.h from including winsock.h, which causes duplicate definitions with winsock2.h
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
 namespace CommonAPI {
 namespace DBus {
 
@@ -33,19 +39,25 @@ inline std::vector<std::string> split(const std::string& s, char delim) {
 
 
 inline std::string getCurrentBinaryFileFQN() {
-    char fqnOfBinary[FILENAME_MAX];
-    char pathToProcessImage[FILENAME_MAX];
+#ifdef WIN32
+       TCHAR result[MAX_PATH];
+       std::basic_string<TCHAR> resultString(result, GetModuleFileName(NULL, result, MAX_PATH));
+       return std::string(resultString.begin(), resultString.end());
+#else
+       char fqnOfBinary[FILENAME_MAX];
+       char pathToProcessImage[FILENAME_MAX];
 
-    sprintf(pathToProcessImage, "/proc/%d/exe", getpid());
-    const ssize_t lengthOfFqn = readlink(pathToProcessImage, fqnOfBinary, sizeof(fqnOfBinary) - 1);
+       sprintf(pathToProcessImage, "/proc/%d/exe", getpid());
+       const ssize_t lengthOfFqn = readlink(pathToProcessImage, fqnOfBinary, sizeof(fqnOfBinary)-1);
 
-    if (lengthOfFqn != -1) {
-        fqnOfBinary[lengthOfFqn] = '\0';
-        return std::string(std::move(fqnOfBinary));
-    } else {
-        //TODO fail of readlink, i.e. it returns -1, sets errno. See http://linux.die.net/man/3/readlink
-        return std::string("");
-    }
+       if (lengthOfFqn != -1) {
+               fqnOfBinary[lengthOfFqn] = '\0';
+               return std::string(std::move(fqnOfBinary));
+       }
+       else {
+               return std::string("");
+       }
+#endif
 }
 
 template<typename _FutureWaitType>