Build TOP Environments

For developer

C API

Debug family(C I/F)
DSO load family(C I/F)
Create/Destroy family(C I/F)
Server node send/receive family(C I/F)
Slave node send/receive family(C I/F)
Server node / slave node reply family(C I/F)
Utility family(C I/F)
Automatic merge callback function(C I/F)

C++ API

Debug family(C/C++ I/F)
ChmCntrl Class
chmstream(ichmstream、ochmstream) Class


C API

The server / client program connected to CHMPX needs to use the CHMPX library.
Include the following header file for development.

#include <chmpx/chmpx.h>

For the link, specify the following as an option.

-lchmpx

Debug family(C I/F)

Format

Description

Parameters

Return value

chmpx_set_debug_file, chmpx_unset_debug_file, chmpx_load_debug_env will return true on success. If it fails, it returns false.

Note

For the environment variables (CHMDBGMODE, CHMDBGFILE), refer to CHMPX details.


DSO load family(C I/F)

Format

Description

Return value

Returns true if it succeeds. If it fails, it returns false.

Note

DSO of the HASH function becomes the function of K2HASH. This function group is the one wrapping the function of K2HASH. For details, refer to K2HASH DSO load related.

Sample

if(!chmpx_load_hash_library("/usr/lib64/myhashfunc.so")){
    return false;
}
    //...
    //...
    //...
chmpx_unload_hash_library();

Create/Destroy family(C I/F)

Format

Description

Parameters

Return value

Note

Be sure to discard the generated CHMPX object handle and received communication information handle.

Sample

chmpx_h    handle;
if(CHM_INVALID_HANDLE == (handle = chmpx_create("myconffile", false, true))){
    return false;
}
    //...
    //...
    //...
if(!chmpx_destroy(handle)){
    return false;
}

Server node send/receive family(C I/F)

Format

Description

Parameters

Return value

Returns true if it succeeds. If it fails, it returns false.

Note

It usually does not start sending from the server node (it will be used for asynchronous communication).
Normally, the server node performs reception processing and uses the communication information handle at the time of reception to reply to the client process. (See later chapter)

Sample

chmpx_h    handle;
if(CHM_INVALID_HANDLE == (handle = chmpx_create("myconffile", true, true))){
    return false;
}
chmpx_pkt_h    pckthandle;
unsigned char*    pbody;
size_t        length;
if(!chmpx_svr_recieve(handle, &pckthandle, &pbody, &length, 100, true)){
    chmpx_destroy(handle);
    return false;
}
    //...
    //...
    //...
    //...
chmpx_pkth_destroy(pckthandle);
if(!chmpx_destroy(handle)){
    return false;
}

Slave node send/receive family(C I/F)

Format

Description

Parameters

Return value

Returns true if it succeeds. If it fails, it returns false.

Note

The slave node will not normally start from the receive sequence (it will be used for asynchronous communications). Normally, the slave node performs transmission processing and waits for a reply to the message handle sent.

Sample

chmpx_h    handle;
if(CHM_INVALID_HANDLE == (handle = chmpx_create("myconffile", false, true))){
    return false;
}
msgid_t    msgid;
if(CHM_INVALID_MSGID == (msgid = chmpx_open(handle, true))){
    chmpx_destroy(handle);
    return false;
}
unsigned char    body[]    = ....;
size_t        blength    = sizeof(body);
chmhash_t    hash    = 0x.....;
long        recievercnt;
if(!chmpx_msg_send(handle, msgid, body, blength, hash, &recievercnt, true)){
    chmpx_close(handle, msgid);
    chmpx_destroy(handle);
    return false;
}
chmpx_pkt_h    pckthandle;
unsigned char*    pbody;
size_t        length;
if(!chmpx_msg_recieve(handle, msgid, &pckthandle, &pbody, &length, 100)){
    chmpx_close(handle, msgid);
    chmpx_destroy(handle);
    return false;
}
    //...
    //...
    //...
    //...
chmpx_pkth_destroy(pckthandle);
if(!chmpx_close(handle, msgid)){
    chmpx_destroy(handle);
    return false;
}
if(!chmpx_destroy(handle)){
    return false;
}

Server node / slave node reply family(C I/F)

Format

Description

Parameters

Return value

Returns true if it succeeds. If it fails, it returns false.

Note

The slave node will not normally reply (it may be used for asynchronous communication). Therefore, this function group is mainly used in the server node.

Sample

chmpx_h    handle;
if(CHM_INVALID_HANDLE == (handle = chmpx_create("myconffile", true, true))){
    return false;
}
chmpx_pkt_h    pckthandle;
unsigned char*    pbody;
size_t        length;
if(!chmpx_svr_recieve(handle, &pckthandle, &pbody, &length, 100, true)){
    chmpx_destroy(handle);
    return false;
}
    //...
    //...
    //...
    //...
unsigned char    body[] = ....;
size_t        blength = sizeof(body);
if(!chmpx_msg_reply(handle, pckthandle, body, blength)){
    chmpx_pkth_destroy(pckthandle);
    chmpx_destroy(handle);
    return false;
}
if(!chmpx_pkth_destroy(pckthandle)){
    chmpx_destroy(handle);
    return false;
}
if(!chmpx_destroy(handle)){
    return false;
}

Utility family(C I/F)

Format

Description

Parameters

Return value

Note

nothing special.


Automatic merge callback function(C I/F)

This is a callback function that can be set by the client on the server node when using the auto merge function. Specify the function defined by the following function type in the chmpx_create_ex function, InitializeOnServer method. If these functions are not specified, processing by callback is not performed, and automatic merging works assuming that it is processed by chmpx.

Format

Description

Parameters

Structure

It is the parameter CHM_MERGE_GETPARAM passed by chm_merge_get_cb.

typedef struct chm_merge_getparam{
    chmhash_t           starthash;
    struct timespec     startts;                // start time for update datas
    struct timespec     endts;                  // end time for update datas
    chmhash_t           target_hash;            // target hash value(0 ... target_max_hash)
    chmhash_t           target_max_hash;        // max target hash value
    long                target_hash_range;      // range for hash value
}CHM_MERGE_GETPARAM, *PCHM_MERGE_GETPARAM;

The following is a description and definition of the member.

Return value

If processing is completed normally, please return true. If processing fails, return false. (If false, merge processing will be interrupted.)

Note

nothing special.


C++ API

The server / client program connected to CHMPX needs to use the CHMPX library.
Include the following header file and other appropriate header file at development time.

#include <chmpx/chmcntrl.h>
#include <chmpx/chmpx.h>


When linking, specify the following as an option.

-lchmpx


The functions for the C ++ language are explained below.


Debug family(C/C++ I/F)

Format

Description

Parameters

Return value

Note

For the environment variables (CHMDBGMODE, CHMDBGFILE), refer to CHMPX details.


ChmCntrl class

Description

Class of CHMPX object.
Through this class, we will send and receive data with CHMPX.
For basic server node programming, create instances of this class and send and receive data.
In the case of a slave node, it creates an instance of this class, opens a message handle, and sends and receives data.
When the operation is completed, close the message handle and destroy this object.

Method

Method Description

Method return value

A prototype whose return value is bool returns true if it succeeds. If it fails, it returns false. The ChmCntrl::Open method returns an open message handle.

Sample (server node)

ChmCntrl*    pchmpx = new ChmCntrl();
if(!pchmpx->InitializeOnServer("myconffile", true)){
    CHM_Delete(pchmpx);
    return false;
}
PCOMPKT        pComPkt;
unsigned char*    pbody;
size_t        length;
if(!pchmpx->Recieve(&pComPkt, &pbody, &length, 0, true)){
    CHM_Delete(pchmpx);
    return false;
}
    //...
    //...
    //...
unsigned char    body[] = ....;
size_t        blength = sizeof(body);
if(!pchmpx->Reply(pComPkt, body, blength)){
    CHM_Free(pComPkt);
    CHM_Delete(pchmpx);
    return false;
}
CHM_Free(pComPkt);
CHM_Delete(pchmpx);

Sample (slave node)

ChmCntrl*    pchmpx = new ChmCntrl();
if(!pchmpx->InitializeOnSlave("myconffile", true)){
    CHM_Delete(pchmpx);
    return false;
}
msgid_t    msgid;
if(CHM_INVALID_MSGID == (msgid = pchmpx->Open(true))){
    CHM_Delete(pchmpx);
    return false;
}
unsigned char    body[] = ....;
size_t        blength = sizeof(body);
chmhash_t    hash = 0x....;
long        recievercnt;
if(!pchmpx->Send(msgid, body, blength, hash, &recievercnt, true)){
    pchmpx->Close(msgid);
    CHM_Delete(pchmpx);
    return false;
}
    //...
    //...
    //...
PCOMPKT        pComPkt;
unsigned char*    pbody;
size_t        length;
if(!pchmpx->Recieve(&pComPkt, &pbody, &length, 0){
    pchmpx->Close(msgid);
    CHM_Delete(pchmpx);
    return false;
}
CHM_Free(pComPkt);
pchmpx->Close(msgid);
CHM_Delete(pchmpx);

Get status

ChmCntrl    chmobj;
if(!chmobj.OnlyAttachInitialize(conffile.c_str(), ctlport)){
    return false;
}
if(!is_self){
    PCHMINFOEX    pInfo = pchmobj->DupAllChmInfo();
        ...
        ...
        ...
    ChmCntrl::FreeDupAllChmInfo(pInfo);
}else{
    PCHMPX    pInfo = pchmobj->DupSelfChmpxInfo();
        ...
        ...
        ...
    ChmCntrl::FreeDupSelfChmpxInfo(pInfo);
}
chmobj.Clean();

chmstream(ichmstream、ochmstream) class

Description

An iostream derived class that provides direct access (send, receive) to a CHMPX object. It is a class that can be used as an iostream by specifying the ChmCntrl class, initializing the stream classes chmstream, ichmstream, ochmstream. It is equivalent to normal std::stringstream and you can use seekpos.
Please refer to std::stringstream for detailed explanation.

Base class

chmstream std::basic_stream
ichmstreamstd::basic_istream
ochmstreamstd::basic_ostream
#### Sample ``` ChmCntrl* pchmpx = new ChmCntrl(); ... ... ... // server node stream test { chmstream strm(&chmobj); string strKey; string strVal; strm >> strKey; strm >> strVal; cout << "Key: " << strKey << " Value: " << strVal << endl; strm.clear(); strm << strKey << endl; strm << strVal << endl; } // slave node stream test { chmstream strm(&chmobj); string strKey = "...."; string strVal = "...."; strm << strKey << endl; strm << strVal << endl; strm.clear(); strm >> strKey; strm >> strVal; cout << "Key: " << strKey << " Value: " << strVal << endl; } ```
Build TOP Environments