From 5c7fe9b838f133f5dbd885da4fff9bae225f7c6b Mon Sep 17 00:00:00 2001
From: Constantin Papizh <p.const@bk.ru>
Date: Tue, 17 Sep 2019 11:52:30 +0300
Subject: [PATCH] Win operability update

---
 include/dap_common.h            | 10 ++--
 libdap.pri                      |  5 ++
 src/dap_common.c                |  6 +--
 src/win32/dap_cpu_monitor.c     |  7 +--
 src/win32/dap_network_monitor.h | 93 ---------------------------------
 src/win32/dap_process_manager.c |  2 +-
 src/win32/dap_process_memory.c  |  4 +-
 src/win32/win32.pri             | 11 ++++
 8 files changed, 31 insertions(+), 107 deletions(-)
 delete mode 100644 src/win32/dap_network_monitor.h
 create mode 100644 src/win32/win32.pri

diff --git a/include/dap_common.h b/include/dap_common.h
index 5e93729df3..ececc13c6e 100755
--- a/include/dap_common.h
+++ b/include/dap_common.h
@@ -127,18 +127,20 @@ DAP_STATIC_INLINE void _dap_aligned_free( void *ptr )
 
 #define DAP_PROTOCOL_VERSION  22
 
+#ifndef _WIN32
 #ifndef MAX
-  #define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
 #ifndef MIN
-  #define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
 #ifndef min
-  #define min MIN
+#define min MIN
 #endif
 #ifndef max
-  #define max MAX
+#define max MAX
+#endif
 #endif
 
 #ifndef LOWORD
diff --git a/libdap.pri b/libdap.pri
index a6d4931bdb..f28f520235 100755
--- a/libdap.pri
+++ b/libdap.pri
@@ -7,6 +7,11 @@ darwin {
     include(src/darwin/darwin.pri)
 }
 
+win32 {
+    include(src/win32/win32.pri)
+    LIBS += -lpsapi
+}
+
 HEADERS += $$PWD/include/dap_common.h \
     $$PWD/include/dap_config.h \
     $$PWD/include/dap_math_ops.h \
diff --git a/src/dap_common.c b/src/dap_common.c
index 219537abf1..b64b42e0d1 100755
--- a/src/dap_common.c
+++ b/src/dap_common.c
@@ -1169,7 +1169,6 @@ void dap_digit_from_string2(const char *num_str, uint8_t *raw, size_t raw_len)
 }
 
 
-#if 0
 /*!
  * \brief Execute shell command silently
  * \param a_cmd command line
@@ -1180,8 +1179,8 @@ int exec_silent(const char * a_cmd) {
     PROCESS_INFORMATION p_info;
     STARTUPINFOA s_info;
 
-    memzero(&s_info, sizeof(s_info));
-    memzero(&p_info, sizeof(p_info));
+    memset(&s_info, 0, sizeof(s_info));
+    memset(&p_info, 0, sizeof(p_info));
 
     s_info.cb = sizeof(s_info);
     char cmdline[512] = {'\0'};
@@ -1198,4 +1197,3 @@ int exec_silent(const char * a_cmd) {
         return -1;
     }
 }
-#endif
diff --git a/src/win32/dap_cpu_monitor.c b/src/win32/dap_cpu_monitor.c
index b8bd1701b1..1857e8f408 100644
--- a/src/win32/dap_cpu_monitor.c
+++ b/src/win32/dap_cpu_monitor.c
@@ -19,7 +19,7 @@
 */
 
 #include <windows.h>
-#include <winnt.h>
+//#include <winnt.h>
 #include <winternl.h>
 
 #include <stdio.h>
@@ -106,8 +106,9 @@ dap_cpu_stats_t dap_cpu_get_stats()
   ULONG outsize;
   uint32_t ntstatus_error;
 
-  ntstatus_error = NtQuerySystemInformation( SystemProcessorPerformanceInformation, &pinfo, 
-                              sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * 64, &outsize );
+  /*ntstatus_error = NtQuerySystemInformation( SystemProcessorPerformanceInformation, &pinfo,
+                              sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * 64, &outsize );*/ // ! ! ! Legacy method, must be replaced
+  ntstatus_error = 0;
 
   if ( ntstatus_error ) {
     log_it(L_ERROR, "NtQuerySystemInformation returned an error %u", ntstatus_error );
diff --git a/src/win32/dap_network_monitor.h b/src/win32/dap_network_monitor.h
deleted file mode 100644
index 009c9187ca..0000000000
--- a/src/win32/dap_network_monitor.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Authors:
- * Anatolii Kurotych <akurotych@gmail.com>
- * DeM Labs Inc.   https://demlabs.net
- * DeM Labs Open source community https://gitlab.demlabs.net/cellframe
- * Copyright  (c) 2017-2019
- * All rights reserved.
-
- This file is part of DAP (Deus Applications Prototypes) the open source project
-
-    DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    DAP is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#pragma once
-
-#include <stdint.h>
-#include <stdbool.h>
-
-//#include <net/if.h>
-//#include <linux/rtnetlink.h>
-
-#define MAX_IP_STR_LEN 15
-#define DAP_ADRESS_UNDEFINED (uint64_t)-1
-
-typedef enum {
-    // like in rtnetlink defines
-    IP_ADDR_ADD,
-    IP_ADDR_REMOVE,
-    IP_ROUTE_ADD,
-    IP_ROUTE_REMOVE,
-    IP_LINK_NEW,
-    IP_LINK_DEL
-} dap_network_monitor_notification_type_t;
-
-
-typedef struct {
-    dap_network_monitor_notification_type_t type;
-    union {
-        struct {
-            char interface_name[IF_NAMESIZE];
-            char s_ip[MAX_IP_STR_LEN + 1];
-            uint32_t ip; // inet_ntoa(*((struct in_addr *)&ipaddr)) for cast to char*
-        } addr; // for IP_ADDR_ADD, IP_ADDR_REMOVE
-        struct {
-            uint64_t destination_address; // 64 bit for checking -1 like not filled variable
-            char s_destination_address[MAX_IP_STR_LEN + 1];
-            uint64_t gateway_address;
-            char s_gateway_address[MAX_IP_STR_LEN + 1];
-            uint8_t protocol;
-            uint8_t netmask;
-        } route; // for IP_ROUTE_ADD, IP_ROUTE_REMOVE
-        struct {
-            char interface_name[IF_NAMESIZE];
-            bool is_up;
-            bool is_running;
-        } link; // for RTM_NEWLINK, RTM_DELLINK
-    };
-} dap_network_notification_t;
-
-typedef void (*dap_network_monitor_notification_callback_t)
-              (const dap_network_notification_t notification);
-
-/**
- * @brief dap_network_monitor_init
- * @param callback
- * @details starts network monitorting
- * @return 0 if successful
- */
-int dap_network_monitor_init(dap_network_monitor_notification_callback_t callback);
-
-/**
- * @brief dap_network_monitor_deinit
- */
-void dap_network_monitor_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/src/win32/dap_process_manager.c b/src/win32/dap_process_manager.c
index 6b0324d32d..2051da95e2 100644
--- a/src/win32/dap_process_manager.c
+++ b/src/win32/dap_process_manager.c
@@ -19,7 +19,7 @@
 */
 
 #include <windows.h>
-#include <winnt.h>
+//#include <winnt.h>
 #include <winternl.h>
 
 #include <stdio.h>
diff --git a/src/win32/dap_process_memory.c b/src/win32/dap_process_memory.c
index 9db5d91275..3614165e49 100644
--- a/src/win32/dap_process_memory.c
+++ b/src/win32/dap_process_memory.c
@@ -18,8 +18,8 @@
     along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <windows.h>
-#include <winnt.h>
+//#include <windows.h>
+//#include <winnt.h>
 #include <winternl.h>
 #include <stdint.h>
 #include <pdh.h>
diff --git a/src/win32/win32.pri b/src/win32/win32.pri
new file mode 100644
index 0000000000..80b325fc64
--- /dev/null
+++ b/src/win32/win32.pri
@@ -0,0 +1,11 @@
+HEADERS += $$PWD/dap_console_manager.h \
+	$$PWD/dap_cpu_monitor.h \
+	$$PWD/dap_process_manager.h \
+	$$PWD/dap_process_memory.h
+	
+SOURCES += $$PWD/dap_console_manager.c \
+	$$PWD/dap_cpu_monitor.c \
+	$$PWD/dap_process_manager.c \
+	$$PWD/dap_process_memory.c
+	
+INCLUDEPATH += $$PWD
-- 
GitLab