Separate library that holds helper functions for the main OMF code.

Revision:
15:32ada27d82b4
Parent:
14:6ed67a160616
Child:
16:3b0bdbfa48ff
--- a/osisoft-omf.cpp	Thu May 03 20:07:42 2018 +0000
+++ b/osisoft-omf.cpp	Wed May 30 15:24:45 2018 +0000
@@ -19,6 +19,7 @@
 #include "config.egressSettings.h"
 #include "config.SSLCertificates.h"
 #include "config.producerToken.h"
+#include "config.customOMFJSONStructures.h"
 
 // ---------------------------------------------------------------------------------------------------
 
@@ -194,4 +195,56 @@
     } else {
         printf("NTP time sync failed; clock set to %i UTC seconds.", DEFAULT_HARD_CODED_UTC_TIME);
     }
+}
+
+// ************************************************************************
+// Sends the dynamic types, static types, assets, and links messages
+// Uses the SEND_ASSETS_AND_LINKS flag found in config.egressSettings and
+// Uses the custom OMF JSON found in config.customOMFJSONStructures.h
+// ************************************************************************
+
+void OMFLib_sendInitialOMFMessages(NetworkInterface* __network_interface) {
+    // Send the DYNAMIC types message, so that these types can be referenced in all later messages
+    printf("\n\r!!!!!!!! Sending DYNAMIC Types message... !!!!!!!!\n\r");
+    //OMFLib_sendMessageToEndpoint(socket, "create", "Type", dynamic_types_message_JSON.c_str());
+    //OMFLib_sendMessageToEndpoint_NoSocketReuse(network, "create", "Type", DYNAMIC_TYPES_MESSAGE_JSON.c_str());
+    OMFLib_sendMessageToEndpoint_NoSocketReuse(__network_interface, "create", "Type", DYNAMIC_TYPES_MESSAGE_JSON.c_str());
+
+    // Send the container message, to instantiate this particular container; we can now directly start sending data to it using its Id
+    printf("\n\r!!!!!!!! Sending Containers message... !!!!!!!!\n\r");
+    //OMFLib_sendMessageToEndpoint(socket, "create", "Container", CONTAINERS_MESSAGE_JSON.c_str());  
+    //OMFLib_sendMessageToEndpoint_NoSocketReuse(network, "create", "Container", CONTAINERS_MESSAGE_JSON.c_str());  
+    OMFLib_sendMessageToEndpoint_NoSocketReuse(__network_interface, "create", "Container", CONTAINERS_MESSAGE_JSON.c_str()); 
+    
+    // Check whether assets and links should be sent!
+    if (SEND_ASSETS_AND_LINKS == true)
+    {
+    
+        // ************************************************************************  
+        // Send the STATIC types message, so that these types can be referenced in all later messages
+        // ************************************************************************
+    
+        printf("\n\r!!!!!!!! Sending STATIC Types message... !!!!!!!!\n\r");
+        //OMFLib_sendMessageToEndpoint(socket, "create", "Type", static_types_message_JSON.c_str()); 
+        //OMFLib_sendMessageToEndpoint_NoSocketReuse(network, "create", "Type", STATIC_TYPES_MESSAGE_JSON.c_str());         
+        OMFLib_sendMessageToEndpoint_NoSocketReuse(__network_interface, "create", "Type", STATIC_TYPES_MESSAGE_JSON.c_str());
+    
+        // ************************************************************************
+        // Send the message to create the PI AF asset; it will not appear in PI AF, though, because it has not yet been positioned...
+        // ************************************************************************
+    
+        printf("\n\r!!!!!!!! Sending Assets message... !!!!!!!!\n\r");
+        //OMFLib_sendMessageToEndpoint(socket, "create", "Data", assets_message_JSON.c_str());
+        //OMFLib_sendMessageToEndpoint_NoSocketReuse(network, "create", "Data", ASSETS_MESSAGE_JSON.c_str());  
+        OMFLib_sendMessageToEndpoint_NoSocketReuse(__network_interface, "create", "Data", ASSETS_MESSAGE_JSON.c_str());
+        
+        // ************************************************************************
+        // Send the message to link the PI AF asset
+        // ************************************************************************
+        
+        printf("\n\r!!!!!!!! Sending Links message... !!!!!!!!\n\r");
+        //OMFLib_sendMessageToEndpoint(socket, "create", "Data", LINKS_MESSAGE_JSON.c_str());
+        //OMFLib_sendMessageToEndpoint_NoSocketReuse(network, "create", "Data", LINKS_MESSAGE_JSON.c_str());  
+        OMFLib_sendMessageToEndpoint_NoSocketReuse(__network_interface, "create", "Data", LINKS_MESSAGE_JSON.c_str());
+    }
 }
\ No newline at end of file