
// Includes.h
#ifndef IncludesHPP
#define IncludesHPP


#include <string> // not <wstring>, <string> contains also wstring
 using namespace std;
#include <cmath>
#include <iostream>

#include <boost/lexical_cast.hpp>

#include <boost/unordered/unordered_map.hpp> //<set> // json and later others?
// for boost you need in mac project prefs: 
// header search path OR user header search path: /Users/pate/svnroot/cpp/boost_1_39_0
//#include <boost/lambda/lambda.hpp>
#include <boost/current_function.hpp>
// use macro BOOST_CURRENT_FUNCTION to get current method name in c++

//#include <boost/date_time/gregorian/gregorian.hpp>
// or just types: 
#include <boost/date_time/gregorian/gregorian_types.hpp>
using namespace boost::gregorian;


//#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
// or just types: 
#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types

#include <boost/format.hpp>

#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
// #include <boost/interprocess/allocators/allocator.hpp>
using namespace boost::interprocess;


#include "4DPluginAPI.h"

#if VERSIONWIN
	// #include "pstdint.h" // VS 2008 needs this
#endif
/*
#if VERSIONWIN

	#include <Windows.h> // for paint box windows drawing
	
	//#include <gdiplus.h>
	//using namespace Gdiplus;
	// //#include <Winuser.h> // where needed?

	// Include Altura toolkit headers
	#include "AsiPort.h"// #include "PPC_h\asiport.h"
	#include "ASI_spec.h"
	#include "Controls.h"
	#include "Asiextrn.h"

	// Define include aliases (for Microsoft Visual C++ 4.0)
// #include "IncludeAliases.h"
#else
 #include <Carbon/Carbon.h>
// #include <curses.h> // for _getch
 #endif
 */

#include <list> // #include <boost/ptr_container/ptr_list.hpp>
// http://www.yolinux.com/TUTORIALS/CppBoostStlPtrList.html



#include "Const.h" // const.h defines what to compile:
//#define MA_Zmq
//#define MA_Sql

// add to win linker input additional dependencies:  ws2_32.lib mswsock.lib \apr-1.lib
// default: ws2_32.lib mswsock.lib
// ../boost_1_45_0;4D Plugin API;ppc_h;Sources/Socket;Sources/Sql;Sources/zmq;C:\cpp\apr-1.4.5\include;Sources/MA_Plugin_x64;Sources/Json;Sources/cJSON
// ws2_32.lib;mswsock.lib;RpcRT4.Lib;C:\cpp\apr-1.4.5\LibD\apr-1.lib;%(AdditionalDependencies)


#include "ConstStr.h" // only in PaintBox.c

#include "Array.h"
#include "PointerArray.h"
#include "Utility.h"

#include "Blob.h" // needed in Socket


// classes - order is important (linked first)

// ZeroMQ
#ifdef MA_Zmq
  //#include <assert.h> // zmq
  //#include <utility>  // zmq
  #if VERSIONWIN
		// #include "C:/cpp/libzmq/src/windows.hpp"
    #if (_MSC_VER < 1600)
      // zmq int64_t and other types for windows, do not use with vc100, only with vc90
      // #include "../zmq/zeromq-plugin/src/stdint.hpp"
      #include "C:/cpp/libzmq/src/stdint.hpp"
    #endif
	#include "zmq.h" // "C:/cpp/libzmq/include/zmq.h" // zmq library windows
  #endif

	#if VERSIONMAC
    #define ZMQ_HAVE_OSX
    #include "../zmq/zeromq-3.2.2/include/zmq.h" // zmq library osx
  #endif


  #include "MA_Zmq.h" // Manage code
  #include "MA_Zmq_Plugin.h"
#endif // MA_Zmq

#include "Socket.h"
#include "Tcp.h"
#include "SocketPlugin.h"

// #include "SharedMemory.h"
// #include "SharedMemPlugin.h"

#include "UtilityPlugin.h"

// apr-util dbd Sql
#ifdef MA_Sql
	#include "Sql.h"
#endif


//  Import the c_JSON library
#include "c_JSON.h"
// file://localhost/Users/pasi/svnroot/cpp/MA_Plugin_x64/Sources/c_JSON/c_JSON.c

// must be last include in this file!
#include "sha2.h"

#ifdef MA_Json
	#include "Json_Plugin.h"
#endif



//  Import the json spirit library
// #include "json_spirit.h"



/*

 // MA_DNS
 "MA_DNS_GetHostName:S",
 "MA_DNS_GetHostByName(&S):S",
 "MA_DNS_GetHostByAddress(&S):S",
 "MA_DNS_GetLocalAddresses(&Y;&Y;&Y)",
 
 // MA_TCP
 "MA_TCP_GetLastErrorText(&L):T",
 "MA_TCP_Connect(&S;&L;&T):L",
 "MA_TCP_Close(&L):T",
 "MA_TCP_Listen(&S;&L;&T):L",
 "MA_TCP_Accept(&L):L",
 "MA_TCP_SendBlob(&L;&O;&L;&L):L",
 "MA_TCP_ReceiveBlob(&L;&O;&L;&L):L",
 "MA_TCP_LookaheadBlob(&L;&O;&L;&L):L",
 "MA_TCP_GetLocalAddress(&L;&S;&L):L",
 "MA_TCP_GetRemoteAddress(&L;&S;&L):L",
 "MA_TCP_GetState(&L):L",
 
 // MA_Message
 "MA_Message_Init(&L;&L;&L):L",
 "MA_Message_Terminate:L",
 "MA_Message_Open(&L):L",
 "MA_Message_Close(&L;&L):L",
 "MA_Message_SetOptions(&L;&T)",
 "MA_Message_Connect(&L;&T):L",
 "MA_Message_Bind(&L;&T):L",
 "MA_Message_Poll(&L;&L;&L):L",
 "MA_Message_SendBlob(&L;&O;&L):L",
 "MA_Message_ReceiveBlob(&L;&O;&L):L",
	"MA_Message_GetLastErrorText(&L):T"
*/

enum{
	// MA_Plugin_x64
	
	eCMD_MA_v12_Register = 1,
	eCMD_MA_v12_IsRegistered,
	eCMD_MA_v12_SetErrorCallback,
	
	eCMD_MA_Util_Sha2,
  
	// Socket
	eCMD_MA_Get_Host_Name,
	eCMD_MA_Get_Host_By_Name,
	eCMD_MA_Get_Host_By_Address,
	eCMD_MA_Get_Local_Addresses,
	
	eCMD_MA_TCP_SQL_ReInitialize,
	eCMD_MA_TCP_GetVersion,
	
	eCMD_MA_TCP_Get_Last_Error_Text,
	eCMD_MA_TCP_Connect,
	eCMD_MA_TCP_Close,
	eCMD_MA_TCP_Listen,
	eCMD_MA_TCP_Accept,
	eCMD_MA_TCP_Send_Blob,
	eCMD_MA_TCP_Receive_Blob,
	eCMD_MA_TCP_Lookahead_Blob,
	eCMD_MA_TCP_Get_Local_Address,
	eCMD_MA_TCP_Get_Remote_Address,
	eCMD_MA_TCP_Get_OS_Socket,
	eCMD_MA_TCP_Get_State,
  
  eCMD_MA_TCP_Set_Poll_Arrays,
  eCMD_MA_TCP_Ceate_Pollset,
  eCMD_MA_TCP_Destroy_Pollset,
  eCMD_MA_TCP_Poll,
  eCMD_MA_TCP_Get_Poll_Counts,
  
	eCMD_MA_Zmq_Test,
	eCMD_MA_Zmq_GetVersion,
	eCMD_MA_Zmq_GetLastErrorText,
	eCMD_MA_Zmq_GetLastErrorNum,
	eCMD_MA_Zmq_GetContext,
	eCMD_MA_Zmq_GetSocketCount,
	eCMD_MA_Zmq_GetSocketValidity,
	eCMD_MA_Zmq_GetSockets,
	eCMD_MA_Zmq_SetPollArrays,
	
	eCMD_MA_Zmq_context_init,
	eCMD_MA_Zmq_context_terminate,
	
	eCMD_MA_Zmq_socket_create,
	eCMD_MA_Zmq_socket_close,
	eCMD_MA_Zmq_socket_opt_set,
	eCMD_MA_Zmq_socket_opt_get,
	eCMD_MA_Zmq_socket_identity_set,
	eCMD_MA_Zmq_socket_identity_get,
	
	eCMD_MA_Zmq_socket_bind,
	eCMD_MA_Zmq_socket_connect,
	
	eCMD_MA_Zmq_send,
	eCMD_MA_Zmq_receive,
	eCMD_MA_Zmq_forward,
  eCMD_MA_Zmq_poll,
	
	/*
	eCMD_MA_Zmq_receive_text,
	eCMD_MA_Zmq_send_text,
	
	eCMD_MA_Zmq_msg_init,
	eCMD_MA_Zmq_msg_init_size,
	eCMD_MA_Zmq_msg_init_data,
	eCMD_MA_Zmq_msg_close,
	eCMD_MA_Zmq_msg_data,
	eCMD_MA_Zmq_msg_size,
	eCMD_MA_Zmq_msg_copy,
	eCMD_MA_Zmq_msg_move,
	*/
	
	/* old or not in use
	 eCMD_MA_TCP_Send, // use only Send Blob
	 eCMD_MA_TCP_Receive,
	 eCMD_MA_TCP_Lookahead,
	 eCMD_MA_TCP_Get_SSL_Verify_Result,
	 eCMD_MA_TCP_Is_Secure_Connection,
	 eCMD_MA_UDP_Open,
	 eCMD_MA_UDP_Listen,
	 eCMD_MA_UDP_Close,
	 eCMD_MA_UDP_Send,
	 eCMD_MA_UDP_Send_Blob,
	 eCMD_MA_UDP_Receive,
	 eCMD_MA_UDP_Receive_Blob,
	 eCMD_MA_UDP_Join_Group,
	 eCMD_MA_UDP_Leave_Group,
	 eCMD_MA_UDP_Set_Max_Router_Hops,
	 eCMD_MA_UDP_Send_To_Self,
	 eCMD_MA_IPC_New_Channel,
	 eCMD_MA_IPC_Delete_Channel,
	 eCMD_MA_IPC_Get_Channel_Name,
	 eCMD_MA_IPC_Send,
	 eCMD_MA_IPC_Broadcast,
	 eCMD_MA_IPC_Receive,
	 eCMD_MA_IPC_Count_Messages,
	 eCMD_MA_IPC_Get_Message_By_Index,
	 eCMD_MA_IPC_Count_Channels,
	 eCMD_MA_IPC_Get_Channel_By_Index,
	 eCMD_MA_IPC_Get_Channel_By_Name
	 */
	
	
	// --- MA_MA_Json 4D Plugin Commands
	eCMD_MA_Json_GetLastErrorText,
	eCMD_MA_Json_GetReferences,
	
	// Supply a block of JSON, and this returns a c_JSON object you can interrogate. Call c_JSON_Delete when finished.
	eCMD_MA_Json_Parse,
	// Render a c_JSON entity to text for transfer/storage. Free the char* when finished.
	eCMD_MA_Json_Print,
	// Render a c_JSON entity to text for transfer/storage without any formatting. Free the char* when finished.
	eCMD_MA_Json_PrintUnformatted,
	// Delete a c_JSON entity and all subentities.
	eCMD_MA_Json_Delete,
	
	// Returns the number of items in an array (or object).
	eCMD_MA_Json_GetArraySize,
	// Retrieve item number "item" from array "array". Returns NULL if unsuccessful.
	eCMD_MA_Json_GetArrayItem,
	// Get item "string" from object. Case insensitive.
	eCMD_MA_Json_GetObjectItem,
	
	eCMD_MA_Json_GetObjectString,
	eCMD_MA_Json_GetObjectLong,
	eCMD_MA_Json_GetObjectReal,
	
  eCMD_MA_Json_GetItemName,
  eCMD_MA_Json_GetItemType,
  
	eCMD_MA_Json_GetItemString,
	eCMD_MA_Json_GetItemBoolean,
	eCMD_MA_Json_GetItemLong,
	eCMD_MA_Json_GetItemReal,
	
	eCMD_MA_Json_GetItemStringArray,		 
	eCMD_MA_Json_GetItemLongArray,
	eCMD_MA_Json_GetItemRealArray,
	
		// These calls create a c_JSON item of the appropriate type.
	eCMD_MA_Json_CreateNull,
	eCMD_MA_Json_CreateTrue,
	eCMD_MA_Json_CreateFalse,
	eCMD_MA_Json_CreateNumber,
	eCMD_MA_Json_CreateString,
	eCMD_MA_Json_CreateArray,
	eCMD_MA_Json_CreateObject,
	
	// These utilities create an Array of count items.
	eCMD_MA_Json_CreateStringArray,		 
	eCMD_MA_Json_CreateLongArray,
	eCMD_MA_Json_CreateRealArray,
	
	
	// Append item to the specified array/object.
	eCMD_MA_Json_AddItemToArray,
	eCMD_MA_Json_AddItemToObject,
	// Append reference to item to the specified array/object. Use this when you want to add an existing c_JSON to a new c_JSON, but don't want to corrupt your existing c_JSON.
	eCMD_MA_Json_AddItemRefToArray,
	eCMD_MA_Json_AddItemRefToObject,
	
	// Remove/Detatch items from Arrays/Objects.
	eCMD_MA_Json_DetachItemFromArray,
	eCMD_MA_Json_DeleteItemFromArray,
	eCMD_MA_Json_DetachItemFromObject,
	eCMD_MA_Json_DeleteItemFromObject,
	
	
	// Update array items.
	eCMD_MA_Json_ReplaceItemInArray,
	eCMD_MA_Json_ReplaceItemInObject,
	
	eCMD_MA_Json_AddNullToObject,
	eCMD_MA_Json_AddTrueToObject,
	eCMD_MA_Json_AddFalseToObject,
	eCMD_MA_Json_AddNumberToObject,
	eCMD_MA_Json_AddStringToObject,
	
  eCMD_MA_SharedMemory,
  eCMD_MA_Microseconds,
  eCMD_MA_Milliseconds,
  eCMD_MA_Seconds,
  eCMD_MA_Markdown,
  eCMD_MA_LuaText,  
  eCMD_MA_LuaBlob // no ',' after last one!  
	
};

#endif



