TcaplusDB TDR Table C++SDK Get Started

The preparations for using the C++ SDK mainly include:

  1. Prepare the environment;
  2. Create an app;
  3. Create a game zone;
  4. Create a table;
  5. Collect environmental information;
  6. Download SDK;
  7. Configure the development environment.

If the above preparations have been completed, they can be skipped.

1. Prepare the Environment

Refer to Create a Cluster to deploy the TcaplusDB cluster, or apply for the TcaplusDB service.

2. Create an App

Refer to Create an App to create an App.

3. Create A Game Zone

Refer to Create a Game Zone to create a game zone (Zone).

4. Create A Table

Refer to Add a Table to add a table.

TDR tables are divided into Generic tables and List tables.

4.1. Generic Table Definition Descriptions

Sample of the Generic table description file: Download.

Content example of the Generic table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

4.2. List Table Definition Descriptions

Sample of the List table description file: Download.

Content example of the List table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name" customattr2="TableType=LIST;ListNum=3">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

The TableType = LIST in customattr2 defined by the table is used to identify the list table. Similarly, the ListNum attribute in customattr2 is used to specify how many elements can be stored in a single List at most.

Note: Since the List table has a built-in primarykey field to store the element serial numbers in the List, users can only define up to 7 primarykey fields for the List table.

5. Collect Environmental Information

When using the C++ SDK, it requires some environment related parameters. See the following table for specific parameters and collection methods.

Parameter Value Getting method
Directory server address list Get directory service address list
App ID Get App ID
App access password Get app access password
Game zone ID Get game zone ID
Table name test

6. Download C++ SDK

For details about the C++ SDK release and download link, see TDR Table SDK Download.

7. Configure the Compilation Development Environment

Environmental dependence Version Description
Operating System CentOS7 X86 System
C++ Version download SDK Download Both C++98 and C11++ are supported
GCC Version download SDK Download GCC 4 and above are supported and can be downloaded on demand, mainly the difference between the abi
gcc-c++ Version download SDK Download yum install -y gcc-c++
Tbase Version download SDK Download TDR dependency package

7.1 Introduction to SDK Directories

  • The include directory is the header file of the SDK. When using the SDK, it needs to include the corresponding header file. All API interfaces have comments, which can be viewed in the header file
  • The lib directory is the SDK static library directory, which needs to be linked statically when compiling
  • The example directory contains the operation examples of all PB and TDR tables. Please refer to the C++SDK Interfaces Instructions for details
  • The bin directory stores TcaplusDB Client tools. Click the link to learn how to use them
  • The cfg directory stores log configuration files used with the TcaplusDB Client tools

7.2 Convert TDR Table XML to C++ Code

  • TSF4G_ HOME: Specify the path of the downloaded Tbase dependency library. The tdr tool is available in the tools directory of this path to convert the database table into C++code
${TSF4G_HOME}/tools/tdr --xml2h -o table_test.h    table_test.xml
${TSF4G_HOME}/tools/tdr --xml2c -o table_test.cpp  table_test.xml

7.3 Compile

Each example has a makefile file, which uses TSF4G HOME and TCAPLUS HOME two environment variables:

  • TSF4G_ HOME: Specify the path of the downloaded Tbase dependency library
  • TCAPLUS_ HOME: Specify the path of the downloaded Tcaplus SDK library

These two environment variables are set in the envcfg.env file under the example directory, which can be modified to specify the correct path, and then source envcfg.env

# ================================================================
#Makefile for tcaplus example
#
# Date:   2016-09-14
#
# Copyright (C) 2016 Architechure IRED TENCENT
#
# ================================================================

CPPFILE=$(wildcard *.cpp)

LIBS += -L $(TSF4G_HOME)/lib -L$(TCAPLUS_HOME)/lib -Wl,-Bstatic -ltcaplusserviceapi -ltsf4g_r -lreadline -lncurses  -lscew -lexpat -Wl,-Bdynamic -lpthread -lanl

INC = -I$(TSF4G_HOME)/include -I$(TCAPLUS_HOME)/include/tcaplus_service -I../../../C++_common_for_tdr1.0

.PHONY: all clean

all:
        g++ -o mytest $(CPPFILE) $(INC) ${LIBS} 

clean:
        rm -f mytest     mytest.log*

8. Use C++ SDK

Please refer to the C++ SDK Interfaces Descriptions for details

9. FAQ

In the process of using the C++ SDK, if you have questions (such as viewing the SDK version, configuring SDK log printing, upgrading the SDK, etc.), or errors, please refer to "FAQ" and "Meaning and Handling of Error Codes".

  1. FAQ document;

  2. Meaning and Handling of Error Codes document;

results matching ""

    No results matching ""