📄 framework_cpp.h
字号:
/***************************************************************** * * * framework_cpp.h * * * * This file is a part of the eXtremeDB-HA Application Framework * * Copyright (c) 2001-2006 McObject LLC * * All Rights Reserved * ***************************************************************** * ++ * * PROJECT: eXtremeDB(tm) (c) 2003 McObject LLC * * SUBSYSTEM: HA support * * MODULE: framework_cpp.h * * ABSTRACT: The sample of wrapper methods for accessing HA communication * channels from within the C++ application * * * VERSION: 1.0 * * HISTORY: * 1.0- 1 SS 03-Oct-2003 Created it was * *****************************************************************/#ifndef _WRAPPER_H_ #define _WRAPPER_H_#include "params.h"/* * * If we don't need to write our own communication channel in C++ * then we can use the framework modules that was already written without any changes. * The only thing we have to do is to write wrapper methods or even better the wrapper * class in order to access the interface of HA communication channels which is written * in pure C. * The short description of the architecture of HA communication channels is placed in * \haframework\framework\framework.c. In fact we need to use explicitly only the 3 functions: * * mco_nw_attach_replica() - is used by the connection server of master * application and is intented for creating and connecting replica channels and attaching * replicas to the master. * * mco_nw_attach_master() - is used by replica application and is intended to * establish the connection and to attach the replica to the master. * * mco_nw_close() - closes all communication channels of MASRER or REPLICA. * * Functions mco_nw_recv() and mco_nw_send() are the implementation of the HA virtual methods * (*mco_xstream_write)() and (*mco_xstream_read)(). The pointers to these functions are * set to the HA interface class, which is inherited by the communication-channel-class as * the BASE classs. * * If we need to write our own communication channels in C++ and don't want to use .c modules * within the application then we have to create our own class of communication channel in the * same way as it is done in framework.c: * *//* * Define this if you want to create your own class of communication channel: */#define CFG_USER_CHANNEL_DEFINED#ifdef CFG_USER_CHANNEL_DEFINED class UserDefinedChannel: public mco_channel_t { public: UserDefinedChannel(); // creates the new channel ~UserDefinedChannel(); // deleteses the new channel // friend int mco_nw_send( mco_channel_h ch, const void* buffer, unsigned buflen, timer_unit timeout); friend int mco_nw_recv( mco_channel_h ch, const void* buffer, unsigned buflen, timer_unit timeout); friend void ErrorHandler( ha_error_h HAerror); // // Initialize the network protocol & base channel descriptor. MCO_RET Init(); // = nw_init() // Set the IO channel to listener state. MCO_RET Listen(const char * nw_dev); // = nw_listen() //Wait for the connection of a remote host to the IO channel. MCO_RET Accept( nw_channel_h ioch, ulong timeout); // = nw_accept() // Connect IO channel to the remote host by it's name. MCO_RET Connect( const char* connect_string, ulong timeout); // = nw_connect() // Low level data transfer. Sends a block of data to the communication channel MCO_RET Send ( const char* buffer, int2 buflen, ulong timeout); // = nw_send () // Low level data transfer. Receives block of data from the communication channel MCO_RET Receive( char* buffer, int2 buflen, int2* recvlen, ulong timeout); // = nw_recv() // Close the communication channel MCO_RET Close(); // = nw_close() private: WORD status; // channel status for example };#endif/* * Then we have to create the interface class which allows us to attach master or replica and * automatically create the new communication channel for the connection. The new instance of the * communication channel should be created as the delegate. The pointer to the new instance is passed * to HA. */ class HaInterface { public: HaInterface(); ~HaInterface(); // // This function includes connection algotrithm dependent on the type of a communication // channel. It attaches connected replica to HA subsystem. MCO_RET AttachReplica( const char* devname, const mco_connection_param_t * params, const char* replica_name, ulong timeout); // = mco_nw_attach_replica() // This function includes connection algotrithm dependent on the type of a communication // channel. It attaches the replica to the connected master. MCO_RET AttachMaster( const char* conn_string, const mco_connection_param_t* params, MCO_E_HA_REPLICA_STOP_REASON* stop_reason, const char* db_name, mco_dictionary_h dict, void* mem_ptr, uint4 total_size, unsigned long timeout); // = mco_nw_attach_master() // If called by the replica the function closes the communication channel. // if called by the master then disconnects all replicas // connected to the master and closes all master/replica communication channels MCO_RET Close (); // = mco_nw_close ()// inline void setDataBase(mco_db_h _db) { db = _db; } inline mco_db_h getDataBase() { return db; }// private: mco_db_h db; // handle to the database instance};#endif // _WRAPPER_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -