Updated on 2023-03-23 GMT+08:00

Initializing the SDK

Init

API Description

This API is used to start and initialize the SDK.

Precautions

  1. Before calling this API, change the name of the HwmSdk.exe file in the HwmSdk folder to your desired name.
  2. You must call this API successfully and receive the callback result before calling other APIs.
  3. Each time the initialization API is called, the SDK is restarted, and all the previous settings and operations are cleared.
  4. This API is an asynchronous API. The return value only indicates whether the API is successfully called. The actual service processing result is returned in the corresponding callback function.

Method Definition

1
HWM_SDK_AGENT_API hwmsdk::HwmErrCode Init(HwmInitInfo *initInfo);

Callback Function

1
virtual void OnInitResult(hwmsdk::HwmErrCode ret, const char* reason, HwmSdkInfo *sdkInfo) {};

Parameter Description

Table 1 HWMJoinConfParam parameters

Parameter

Mandatory

Type

Description

exePath

This parameter is mandatory for the x64 platform and is not required for the 32-bit platform.

char[]

SDK startup path, that is, the absolute path of the .exe file in the HwmSdk folder of the SDK package. Before calling this API, change the name of the HwmSdk.exe file in the HwmSdk folder of the SDK package to your desired name. Assume that the path of the HwmSdk folder is D:\MyApp\SDK\HwmSdk\ and the name of the .exe file is MySdk.exe. Then set this parameter to D:\MyApp\SDK\HwmSdk\MySdk.exe.

UTF-8 encoding is required.

logPath

Yes

char[]

SDK log path. If this parameter is not set, the default path is used.

UTF-8 encoding is required.

userDataPath

Yes

char[]

SDK user data path. If this parameter is not set, the default path is used.

UTF-8 encoding is required.

appId

Yes

char[]

App ID. For details about how to request an app ID, see Requesting an App ID in Developer Guide.

notify

Yes

HwmAgentNotify

Notification object, which is the object of the class inherited from the base class HwmAgentNotify.

callback

Yes

HwmAgentCallback

API callback object, which is the object of the class inherited from the base class HwmAgentCallback.

authType

Yes

HwmAuthType

Authentication mode.

siteType

No

HwmSiteType

Site type. The default value is 0, indicating that Chinese mainland site is used.

logKeepDays

No

unsigned int

Log storage duration. Valid value range is 3–30. The default value is 0. 0 indicates that logs are not deleted by day.

Note: 1 and 2 will be converted to 3, and the values greater than 30 will be converted to 30.

preferredCamera

No

char[]

Preferred camera list. After this parameter is set, the first available camera is selected based on the sequence in the list when the camera is opened for the first time. This parameter can be left empty. If it is left empty, available cameras are enabled in the default sequence.

Table 2 Enumerated values of HwmAuthType

Enumerated Value

Description

HWM_AUTH_TYPE_ACCOUNT_AND_PASSWORD

Account and password authentication.

HWM_AUTH_TYPE_APPID

App ID authentication.

Table 3 Enumerated values of HwmSiteType

Enumerated Value

Description

SITE_TYPE_CHINA

Chinese mainland.

SITE_TYPE_AP

Asia Pacific.

Table 4 HwmSdkInfo parameters

Parameter

Type

Description

version

char[]

SDK version number.

App ID authentication mode is recommended. For details about how to request an app ID, see section "Requesting an App ID" in Developer Guide.

Return Values

Table 5 Return values

Type

Description

HwmErrCode

If 0 is returned, the operation is successful. If other values are returned, the operation fails. For details about values returned upon failures, see Common Error Codes.

Sample Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Create a notification processing object.
static demoNotifyProc *notifyObj = new demoNotifyProc();
// Create a callback function processing object.
static demoCallbackProc *callbackObj = new demoCallbackProc();

/**
* Call the initialization API and start the application.
*/
int CdemoBeforeLoginDlg::Init()
{
    // Assemble the input parameter structure.
    hwmsdkagent::HwmInitInfo initParam;
    memset(&initParam, 0, sizeof(HwmInitInfo));
 
    //Set the SDK path. Assume that the directory of the HwmSdk folder is E:\\Hello_World\\debug\\win32\\, and the name of the .exe file is MySdk.exe. Then set the SDK path as follows:
    std::string path = "E:\\Hello_World\\debug\\win32\\HwmSdk\\MySdk.exe";
    //Convert the SDK path into the UTF-8 format and copy it to initParam. The conversion code is omitted here.
    strcpy_s(initParam.exePath, HWM_MAX_FILE_PATH_LEN, path.c_str());
    //Specify the log path, convert the path into the UTF-8 format, and copy the converted path to initParam. The conversion code is omitted here.
    std::string logPath = "E:\\Hello_World\\debug\\win32\\MySdk\\log\\";
    strcpy_s(initParam.logPath, HWM_MAX_FILE_PATH_LEN, logPath.c_str());
    //Specify the data path, convert the path into the UTF-8 format, and copy the converted path to initParam. The conversion code is omitted here.
    std::string userDataPath = "E:\\Hello_World\\debug\\win32\\MySdk\\UserData\\";
    strcpy_s(initParam.userDataPath, HWM_MAX_FILE_PATH_LEN, userDataPath.c_str());

    // Pass the requested enterprise app ID.
    string appId("fdb8e4699586458bbd10c834872dcc62");
    strncpy_s(initParam.appId, appId.c_str(), HWM_MAX_APPID_LEN);
    initParam.notify = notifyObj;
    initParam.callback = callbackObj;
    initParam.authType = hwmsdkagent::HWM_AUTH_TYPE_APPID;
    int ret = hwmsdkagent::Init(&initParam);
 
    return ret;
}
  • The sample code in the typical scenario and API reference is pseudo code and cannot be directly used.
  • For details about the definitions of the message notification processing class demoNotifyProc and callback function processing class demoCallbackProc, see the demo code in the SDK package.