]> git.seodisparate.com - UDPConnection/commitdiff
Rename enum types to avoid name conflict
authorStephen Seo <seo.disparate@gmail.com>
Thu, 19 Sep 2019 01:58:19 +0000 (10:58 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 19 Sep 2019 01:58:19 +0000 (10:58 +0900)
cpp_impl/src/UDPC_Defines.hpp
cpp_impl/src/UDPConnection.cpp
cpp_impl/src/UDPConnection.h
cpp_impl/src/test/UDPC_NetworkTest.cpp

index 0de0a1726a8177e7dca79e084e9951c41eb7db30..ee9f8f5afd43dcc2d97ca40d4c7f2ba9bf2d8747 100644 (file)
@@ -128,54 +128,54 @@ private:
     template<typename... Targs>
     void log_impl(UDPC_LoggingType type, Targs... args) { // {{{
         switch(loggingType.load()) {
-        case UDPC_LoggingType::SILENT:
+        case UDPC_LoggingType::UDPC_SILENT:
             return;
-        case UDPC_LoggingType::ERROR:
-            if(type == UDPC_LoggingType::ERROR) {
+        case UDPC_LoggingType::UDPC_ERROR:
+            if(type == UDPC_LoggingType::UDPC_ERROR) {
                 std::cerr << "ERROR: ";
             } else {
                 return;
             }
             break;
-        case UDPC_LoggingType::WARNING:
+        case UDPC_LoggingType::UDPC_WARNING:
             switch(type) {
-            case UDPC_LoggingType::ERROR:
+            case UDPC_LoggingType::UDPC_ERROR:
                 std::cerr << "ERROR: ";
                 break;
-            case UDPC_LoggingType::WARNING:
+            case UDPC_LoggingType::UDPC_WARNING:
                 std::cerr << "WARNING: ";
                 break;
             default:
                 return;
             }
             break;
-        case UDPC_LoggingType::VERBOSE:
+        case UDPC_LoggingType::UDPC_VERBOSE:
             switch(type) {
-            case UDPC_LoggingType::ERROR:
+            case UDPC_LoggingType::UDPC_ERROR:
                 std::cerr << "ERROR: ";
                 break;
-            case UDPC_LoggingType::WARNING:
+            case UDPC_LoggingType::UDPC_WARNING:
                 std::cerr << "WARNING: ";
                 break;
-            case UDPC_LoggingType::VERBOSE:
+            case UDPC_LoggingType::UDPC_VERBOSE:
                 std::cerr << "VERBOSE: ";
                 break;
             default:
                 return;
             }
             break;
-        case UDPC_LoggingType::INFO:
+        case UDPC_LoggingType::UDPC_INFO:
             switch(type) {
-            case UDPC_LoggingType::ERROR:
+            case UDPC_LoggingType::UDPC_ERROR:
                 std::cerr << "ERROR: ";
                 break;
-            case UDPC_LoggingType::WARNING:
+            case UDPC_LoggingType::UDPC_WARNING:
                 std::cerr << "WARNING: ";
                 break;
-            case UDPC_LoggingType::VERBOSE:
+            case UDPC_LoggingType::UDPC_VERBOSE:
                 std::cerr << "VERBOSE: ";
                 break;
-            case UDPC_LoggingType::INFO:
+            case UDPC_LoggingType::UDPC_INFO:
                 std::cerr << "INFO: ";
                 break;
             default:
@@ -196,28 +196,28 @@ private:
     template<typename T, typename... Targs>
     void log_impl_next(UDPC_LoggingType type, T value, Targs... args) { // {{{
         switch(loggingType.load()) {
-        case UDPC_LoggingType::SILENT:
+        case UDPC_LoggingType::UDPC_SILENT:
             return;
-        case UDPC_LoggingType::ERROR:
-            if(type == UDPC_LoggingType::ERROR) {
+        case UDPC_LoggingType::UDPC_ERROR:
+            if(type == UDPC_LoggingType::UDPC_ERROR) {
                 std::cerr << value;
             }
             break;
-        case UDPC_LoggingType::WARNING:
-            if(type == UDPC_LoggingType::ERROR || type == UDPC_LoggingType::WARNING) {
+        case UDPC_LoggingType::UDPC_WARNING:
+            if(type == UDPC_LoggingType::UDPC_ERROR || type == UDPC_LoggingType::UDPC_WARNING) {
                 std::cerr << value;
             }
             break;
-        case UDPC_LoggingType::VERBOSE:
-            if(type == UDPC_LoggingType::ERROR || type == UDPC_LoggingType::WARNING
-                    || type == UDPC_LoggingType::VERBOSE) {
+        case UDPC_LoggingType::UDPC_VERBOSE:
+            if(type == UDPC_LoggingType::UDPC_ERROR || type == UDPC_LoggingType::UDPC_WARNING
+                    || type == UDPC_LoggingType::UDPC_VERBOSE) {
                 std::cerr << value;
             }
             break;
-        case UDPC_LoggingType::INFO:
-            if(type == UDPC_LoggingType::ERROR || type == UDPC_LoggingType::WARNING
-                    || type == UDPC_LoggingType::VERBOSE
-                    || type == UDPC_LoggingType::INFO) {
+        case UDPC_LoggingType::UDPC_INFO:
+            if(type == UDPC_LoggingType::UDPC_ERROR || type == UDPC_LoggingType::UDPC_WARNING
+                    || type == UDPC_LoggingType::UDPC_VERBOSE
+                    || type == UDPC_LoggingType::UDPC_INFO) {
                 std::cerr << value;
             }
             break;
index d97152a6a10efc2f93c1d1589135787adb8e2955..0f9c03ab091a5edd704cd54f77d78821c3d65072 100644 (file)
@@ -136,9 +136,9 @@ flags(),
 isAcceptNewConnections(true),
 protocolID(UDPC_DEFAULT_PROTOCOL_ID),
 #ifndef NDEBUG
-loggingType(INFO),
+loggingType(UDPC_INFO),
 #else
-loggingType(WARNING),
+loggingType(UDPC_WARNING),
 #endif
 atostrBufIndex(0),
 rng_engine(),
@@ -170,7 +170,7 @@ void UDPC::Context::update_impl() {
             if(temp_dt_fs >= UDPC::CONNECTION_TIMEOUT) {
                 removed.push_back(iter->first);
                 log(
-                    UDPC_LoggingType::VERBOSE,
+                    UDPC_LoggingType::UDPC_VERBOSE,
                     "Timed out connection with ",
                     UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                     ", port = ",
@@ -184,7 +184,7 @@ void UDPC::Context::update_impl() {
             if(iter->second.flags.test(1) && !iter->second.flags.test(2)) {
                 // good mode, bad rtt
                 log(
-                    UDPC_LoggingType::INFO,
+                    UDPC_LoggingType::UDPC_INFO,
                     "Switching to bad mode in connection with ",
                     UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                     ", port = ",
@@ -210,7 +210,7 @@ void UDPC::Context::update_impl() {
                     iter->second.toggleTimer = std::chrono::steady_clock::duration::zero();
                     iter->second.toggledTimer = std::chrono::steady_clock::duration::zero();
                     log(
-                        UDPC_LoggingType::INFO,
+                        UDPC_LoggingType::UDPC_INFO,
                         "Switching to good mode in connection with ",
                         UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                         ", port = ",
@@ -300,14 +300,14 @@ void UDPC::Context::update_impl() {
                     sizeof(struct sockaddr_in6));
                 if(sentBytes != 20) {
                     log(
-                        UDPC_LoggingType::ERROR,
+                        UDPC_LoggingType::UDPC_ERROR,
                         "Failed to send packet to initiate connection to ",
                         UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                         ", port = ",
                         iter->second.port);
                     continue;
                 } else {
-                    log(UDPC_LoggingType::INFO, "Sent initiate connection to ",
+                    log(UDPC_LoggingType::UDPC_INFO, "Sent initiate connection to ",
                         UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                         ", port = ",
                         iter->second.port);
@@ -342,7 +342,7 @@ void UDPC::Context::update_impl() {
                     sizeof(struct sockaddr_in6));
                 if(sentBytes != 20) {
                     log(
-                        UDPC_LoggingType::ERROR,
+                        UDPC_LoggingType::UDPC_ERROR,
                         "Failed to send packet to initiate connection to ",
                         UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                         ", port = ",
@@ -386,7 +386,7 @@ void UDPC::Context::update_impl() {
                 sizeof(struct sockaddr_in6));
             if(sentBytes != 20) {
                 log(
-                    UDPC_LoggingType::ERROR,
+                    UDPC_LoggingType::UDPC_ERROR,
                     "Failed to send heartbeat packet to ",
                     UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                     ", port = ",
@@ -445,7 +445,7 @@ void UDPC::Context::update_impl() {
                 sizeof(struct sockaddr_in6));
             if(sentBytes != 20 + pInfo.dataSize) {
                 log(
-                    UDPC_LoggingType::ERROR,
+                    UDPC_LoggingType::UDPC_ERROR,
                     "Failed to send packet to ",
                     UDPC_atostr((UDPC_HContext)this, iter->first.addr),
                     ", port = ",
@@ -508,7 +508,7 @@ void UDPC::Context::update_impl() {
     } else if(bytes < 20) {
         // packet size is too small, invalid packet
         log(
-            UDPC_LoggingType::INFO,
+            UDPC_LoggingType::UDPC_INFO,
             "Received packet is smaller than header, ignoring packet from ",
             UDPC_atostr((UDPC_HContext)this, receivedData.sin6_addr),
             ", port = ",
@@ -520,7 +520,7 @@ void UDPC::Context::update_impl() {
     if(temp != protocolID) {
         // Invalid protocol id in packet
         log(
-            UDPC_LoggingType::INFO,
+            UDPC_LoggingType::UDPC_INFO,
             "Received packet has invalid protocol id, ignoring packet from ",
             UDPC_atostr((UDPC_HContext)this, receivedData.sin6_addr),
             ", port = ",
@@ -548,7 +548,7 @@ void UDPC::Context::update_impl() {
             // is receiving as server, connection did not already exist
             UDPC::ConnectionData newConnection(true, this, receivedData.sin6_addr, receivedData.sin6_scope_id, ntohs(receivedData.sin6_port));
             log(
-                UDPC_LoggingType::VERBOSE,
+                UDPC_LoggingType::UDPC_VERBOSE,
                 "Establishing connection with client ",
                 UDPC_atostr((UDPC_HContext)this, receivedData.sin6_addr),
                 ", port = ",
@@ -580,7 +580,7 @@ void UDPC::Context::update_impl() {
             iter->second.id = conID;
             iter->second.flags.set(4);
             log(
-                UDPC_LoggingType::VERBOSE,
+                UDPC_LoggingType::UDPC_VERBOSE,
                 "Established connection with server ",
                 UDPC_atostr((UDPC_HContext)this, receivedData.sin6_addr),
                 ", port = ",
@@ -601,7 +601,7 @@ void UDPC::Context::update_impl() {
 
     // packet is valid
     log(
-        UDPC_LoggingType::INFO,
+        UDPC_LoggingType::UDPC_INFO,
         "Received valid packet from ",
         UDPC_atostr((UDPC_HContext)this, receivedData.sin6_addr),
         ", port = ",
@@ -627,7 +627,7 @@ void UDPC::Context::update_impl() {
             iter->second.flags.set(2, iter->second.rtt <= UDPC::GOOD_RTT_LIMIT);
 
             log(
-                UDPC_LoggingType::INFO,
+                UDPC_LoggingType::UDPC_INFO,
                 "RTT: ",
                 UDPC::durationToFSec(iter->second.rtt) * 1000.0f,
                 " milliseconds");
@@ -660,7 +660,7 @@ void UDPC::Context::update_impl() {
                 if(duration > UDPC::PACKET_TIMEOUT_TIME) {
                     if(sentIter->dataSize <= 20) {
                         log(
-                            UDPC_LoggingType::INFO,
+                            UDPC_LoggingType::UDPC_INFO,
                             "Timed out packet has no payload (probably "
                             "heartbeat packet), ignoring it");
                         sentIter->flags |= 0x8;
@@ -695,7 +695,7 @@ void UDPC::Context::update_impl() {
             if((iter->second.ack & (0x80000000 >> (diff - 1))) != 0) {
                 // already received packet
                 log(
-                    UDPC_LoggingType::INFO,
+                    UDPC_LoggingType::UDPC_INFO,
                     "Received packet is already marked as received, ignoring it");
                 return;
             }
@@ -709,7 +709,7 @@ void UDPC::Context::update_impl() {
             if((iter->second.ack & (0x80000000 >> (diff - 1))) != 0) {
                 // already received packet
                 log(
-                    UDPC_LoggingType::INFO,
+                    UDPC_LoggingType::UDPC_INFO,
                     "Received packet is already marked as received, ignoring it");
                 return;
             }
@@ -724,14 +724,14 @@ void UDPC::Context::update_impl() {
     } else {
         // already received packet
         log(
-            UDPC_LoggingType::INFO,
+            UDPC_LoggingType::UDPC_INFO,
             "Received packet is already marked as received, ignoring it");
         return;
     }
 
     if(isOutOfOrder) {
         log(
-            UDPC_LoggingType::VERBOSE,
+            UDPC_LoggingType::UDPC_VERBOSE,
             "Received packet is out of order");
     }
 
@@ -751,7 +751,7 @@ void UDPC::Context::update_impl() {
 
         if(iter->second.receivedPkts.size() == iter->second.receivedPkts.capacity()) {
             log(
-                UDPC_LoggingType::WARNING,
+                UDPC_LoggingType::UDPC_WARNING,
                 "receivedPkts is full, removing oldest entry to make room");
             iter->second.receivedPkts.pop();
         }
@@ -759,7 +759,7 @@ void UDPC::Context::update_impl() {
         iter->second.receivedPkts.push(recPktInfo);
     } else if(bytes == 20) {
         log(
-            UDPC_LoggingType::VERBOSE,
+            UDPC_LoggingType::UDPC_VERBOSE,
             "Received packet has no payload (probably heartbeat packet)");
     }
 }
@@ -887,14 +887,14 @@ UDPC_HContext UDPC_init(UDPC_ConnectionId listenId, int isClient) {
     UDPC::Context *ctx = new UDPC::Context(false);
     ctx->flags.set(1, isClient != 0);
 
-    ctx->log(UDPC_LoggingType::INFO, "Got listen addr ",
+    ctx->log(UDPC_LoggingType::UDPC_INFO, "Got listen addr ",
         UDPC_atostr((UDPC_HContext)ctx, listenId.addr));
 
     // create socket
     ctx->socketHandle = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
     if(ctx->socketHandle <= 0) {
         // TODO maybe different way of handling init fail
-        ctx->log(UDPC_LoggingType::ERROR, "Failed to create socket");
+        ctx->log(UDPC_LoggingType::UDPC_ERROR, "Failed to create socket");
         delete ctx;
         return nullptr;
     }
@@ -914,7 +914,7 @@ UDPC_HContext UDPC_init(UDPC_ConnectionId listenId, int isClient) {
     if(bind(ctx->socketHandle, (const struct sockaddr *)&ctx->socketInfo,
             sizeof(struct sockaddr_in6)) < 0) {
         // TODO maybe different way of handling init fail
-        ctx->log(UDPC_LoggingType::ERROR, "Failed to bind socket");
+        ctx->log(UDPC_LoggingType::UDPC_ERROR, "Failed to bind socket");
         CleanupSocket(ctx->socketHandle);
         delete ctx;
         return nullptr;
@@ -940,13 +940,13 @@ UDPC_HContext UDPC_init(UDPC_ConnectionId listenId, int isClient) {
     {
 #endif
         // TODO maybe different way of handling init fail
-        ctx->log(UDPC_LoggingType::ERROR, "Failed to set nonblocking on socket");
+        ctx->log(UDPC_LoggingType::UDPC_ERROR, "Failed to set nonblocking on socket");
         CleanupSocket(ctx->socketHandle);
         delete ctx;
         return nullptr;
     }
 
-    ctx->log(UDPC_LoggingType::INFO, "Initialized UDPC");
+    ctx->log(UDPC_LoggingType::UDPC_INFO, "Initialized UDPC");
 
     return (UDPC_HContext) ctx;
 }
@@ -960,7 +960,7 @@ UDPC_HContext UDPC_init_threaded_update(UDPC_ConnectionId listenId,
     ctx->flags.set(0);
     ctx->thread = std::thread(UDPC::threadedUpdate, ctx);
 
-    ctx->log(UDPC_LoggingType::INFO, "Initialized threaded UDPC");
+    ctx->log(UDPC_LoggingType::UDPC_INFO, "Initialized threaded UDPC");
 
     return (UDPC_HContext) ctx;
 }
@@ -992,7 +992,7 @@ void UDPC_client_initiate_connection(UDPC_HContext ctx, UDPC_ConnectionId connec
         return;
     }
 
-    c->log(UDPC_LoggingType::INFO, "client_initiate_connection: Got peer a = ",
+    c->log(UDPC_LoggingType::UDPC_INFO, "client_initiate_connection: Got peer a = ",
         UDPC_atostr((UDPC_HContext)ctx, connectionId.addr),
         ", p = ", connectionId.port);
 
@@ -1013,9 +1013,9 @@ void UDPC_client_initiate_connection(UDPC_HContext ctx, UDPC_ConnectionId connec
             addrConIter = insertResult.first;
         }
         addrConIter->second.insert(connectionId);
-        c->log(UDPC_LoggingType::VERBOSE, "client_initiate_connection: Initiating connection...");
+        c->log(UDPC_LoggingType::UDPC_VERBOSE, "client_initiate_connection: Initiating connection...");
     } else {
-        c->log(UDPC_LoggingType::ERROR, "client_initiate_connection: Already connected to peer");
+        c->log(UDPC_LoggingType::UDPC_ERROR, "client_initiate_connection: Already connected to peer");
     }
 }
 
@@ -1051,7 +1051,7 @@ void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
     auto iter = c->conMap.find(destinationId);
     if(iter == c->conMap.end()) {
         c->log(
-            UDPC_LoggingType::ERROR,
+            UDPC_LoggingType::UDPC_ERROR,
             "Failed to add packet to queue, no established connection "
             "with recipient");
         return;
@@ -1146,7 +1146,7 @@ uint32_t UDPC_set_protocol_id(UDPC_HContext ctx, uint32_t id) {
 UDPC_LoggingType UDPC_set_logging_type(UDPC_HContext ctx, UDPC_LoggingType loggingType) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c) {
-        return UDPC_LoggingType::SILENT;
+        return UDPC_LoggingType::UDPC_SILENT;
     }
     return static_cast<UDPC_LoggingType>(c->loggingType.exchange(loggingType));
 }
index 1ae115becea2538aa9dcd40ead8e35fdde982de4..cac304245658965752698b1209bcb03cbc69653a 100644 (file)
@@ -48,7 +48,7 @@ extern "C" {
 struct UDPC_Context;
 typedef struct UDPC_Context *UDPC_HContext;
 
-typedef enum { SILENT, ERROR, WARNING, VERBOSE, INFO } UDPC_LoggingType;
+typedef enum { UDPC_SILENT, UDPC_ERROR, UDPC_WARNING, UDPC_VERBOSE, UDPC_INFO } UDPC_LoggingType;
 
 typedef struct {
     struct in6_addr addr;
index 9e617f299965c1367e198ccdf96335e611e73b5e..ab9df14dd76baa01834278b21f1c9de4fb8c9aea 100644 (file)
@@ -99,7 +99,7 @@ int main(int argc, char **argv) {
         puts("ERROR: context is NULL");
         return 1;
     }
-    UDPC_set_logging_type(context, UDPC_LoggingType::INFO);
+    UDPC_set_logging_type(context, UDPC_LoggingType::UDPC_INFO);
     unsigned int tick = 0;
     while(true) {
         std::this_thread::sleep_for(std::chrono::seconds(1));