Bean工厂申明 factory.h:
#pragma once
#include "stdafx.h"
#include "MT4ManagerAPI.h"
/*************************************************
*将GB2312编码的字符串转为UTF-8编码
*输入:
*p:指向待转码字符串
*返回:
*指向已转码字符串的指针
*过程:
*将GB2312转为Unicode编码
*再将Unicode转为UTF-8
*************************************************/
const char* Gb2312ToUtf8(const char* p);
/*************************************************
*将UTF-8编码的字符串转为GB2312编码
*输入:
*p:指向待转码字符串
*返回:
*指向已转码字符串的指针
*过程:
*将UTF-8转为Unicode编码
*再将Unicode转为GB2312
*************************************************/
const char* Utf8ToGb2312(const char* p);
/*
* 获取品种组
*/
jobject getConSymbolGroup(JNIEnv* env, jclass clazz, ConSymbolGroup tr);
/*
* 获取节日
*/
jobject getConHoliday(JNIEnv* env, jclass clazz, ConHoliday tr);
/*
* Symbol session
*/
jobject getConSession(JNIEnv* env, jclass clazz, ConSession tr);
/*
* 获取symbol sessions
*/
jobject getConSessions(JNIEnv* env, jclass clazz, ConSessions tr);
/*
* 获取品种
*/
jobject getConSymbol(JNIEnv* env, jclass clazz, ConSymbol tr);
/*
* Security group configuration for client group
*/
jobject getConGroupSec(JNIEnv* env, jclass clazz, ConGroupSec tr);
/*
* Special securities configurations for client group
*/
jobject getConGroupMargin(JNIEnv* env, jclass clazz, ConGroupMargin tr);
/*
* 获取用户组
*/
jobject getConGroup(JNIEnv* env, jclass clazz, ConGroup tr);
/*
* 获取交易记录
*/
jobject getTradeRecord(JNIEnv* env, jclass clazz, TradeRecord tr);
/*
* 获取Manange 安全组
*/
jobject getConManagerSec(JNIEnv* env, jclass clazz, ConManagerSec tr);
/*
* 获取Manange权限
*/
jobject getConManager(JNIEnv* env, jclass clazz, ConManager tr);
/*
* 获取数据源
*/
jobject getConFeeder(JNIEnv* env, jclass clazz, ConFeeder tr);
/**
* 资讯配置
*/
jobject getLiveInfoFile(JNIEnv* env, jclass clazz, LiveInfoFile tr);
/**
* 资讯配置
*/
jobject getpConLiveUpdate(JNIEnv* env, jclass clazz, ConLiveUpdate tr);
/**
* 同步配置
*/
jobject getConSync(JNIEnv* env, jclass clazz, ConSync tr);
/**
* 品种信息
*/
jobject getSymbolInfo(JNIEnv* env, jclass clazz, SymbolInfo tr);
/**
* 服务器日记信息
*/
jobject getServerLog(JNIEnv* env, jclass clazz, ServerLog tr);
/**
* 用户记录
*/
jobject getUserRecord(JNIEnv* env, jclass clazz, UserRecord tr);
/*
*获取用户记录
*/
UserRecord* getUserRecordFromObject(JNIEnv* env, jobject userRecord);
/*
*获取用户组操作
*/
GroupCommandInfo* getGroupCommandInfoFromObject(JNIEnv* env, jobject info);
/*
* 在线用户记录
*/
jobject getOnlineRecord(JNIEnv* env, jclass clazz, OnlineRecord tr);
/*
*获取交易命令
*/
TradeTransInfo* getTradeTransInfoFromObject(JNIEnv* env, jobject tradeTransInfo);
/*
* 获取请求记录
*/
jobject getRequestInfo(JNIEnv* env, jclass clazz, RequestInfo tr);
/*
* 获取请求信息
*/
jobject getTradeTransInfo(JNIEnv* env, jclass clazz, TradeTransInfo tr);
/*
*获取保证金等级信息
*/
jobject getMarginLevel(JNIEnv* env, jclass clazz, MarginLevel tr);
/*
* 获取品种组
*/
jobject getConSymbolGroup(JNIEnv* env, jclass clazz, ConSymbolGroup tr);
/*
* 获取报价
*/
jobject getTickInfo(JNIEnv* env, jclass clazz, TickInfo tr);
/*
* 获取图表参数
*/
ChartInfo* getChartInfoFromObject(JNIEnv* env, jobject chartInfo);
/*
* 获取K线
*/
jobject getRateInfo(JNIEnv* env, jclass clazz, long timesign, RateInfo tr);
/*
* 获取品种报价
*/
TickRequest* getTickRequestFromObject(JNIEnv* env, jobject tickRequest);
/*
* 获取报价数据
*/
jobject getTickRecord(JNIEnv* env, jclass clazz, TickRecord tr);
Bean工厂factory.cpp:
#include "factory.h"
const char* Gb2312ToUtf8(const char* p) {
DWORD dwNum = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
char* psText;
wchar_t* pwText = (wchar_t*)malloc(dwNum * sizeof(wchar_t));
if (NULL == pwText) {
return NULL;
}
dwNum = MultiByteToWideChar(CP_ACP, 0, p, -1, pwText, dwNum);
dwNum = WideCharToMultiByte(CP_UTF8, 0, pwText, -1, NULL, 0, NULL, NULL);
psText = (char*)malloc(dwNum * sizeof(char));
dwNum = WideCharToMultiByte(CP_UTF8, 0, pwText, -1, psText, dwNum, NULL, NULL);
free(pwText);
return psText;
}
const char* Utf8ToGb2312(const char* p) {
DWORD dwNum = MultiByteToWideChar(CP_UTF8, 0, p, -1, NULL, 0);
char* psText;
wchar_t* pwText = (wchar_t*)malloc(dwNum * sizeof(wchar_t));
if (NULL == pwText) {
return NULL;
}
dwNum = MultiByteToWideChar(CP_UTF8, 0, p, -1, pwText, dwNum);
dwNum = WideCharToMultiByte(CP_ACP, 0, pwText, -1, NULL, 0, NULL, NULL);
psText = (char*)malloc(dwNum * sizeof(char));
dwNum = WideCharToMultiByte(CP_ACP, 0, pwText, -1, psText, dwNum, NULL, NULL);
free(pwText);
return psText;
}
/*
* use javap -s class to find method signature
*/
static jmethodID getMethod(JNIEnv* env, jclass clazz, const char* methodName, const char* sig) {
jmethodID method = env->GetMethodID(clazz, methodName, sig);
return method;
}
/*
* 获取品种组
*/
jobject getConSymbolGroup(JNIEnv* env, jclass clazz, ConSymbolGroup tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setName", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.name));
}
method = getMethod(env, clazz, "setDescription", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.description));
}
return record;
}
/*
* 获取节日
*/
jobject getConHoliday(JNIEnv* env, jclass clazz, ConHoliday tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setYear", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.year);
}
method = getMethod(env, clazz, "setMonth", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.month);
}
method = getMethod(env, clazz, "setDay", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.day);
}
method = getMethod(env, clazz, "setFrom", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.from);
}
method = getMethod(env, clazz, "setTo", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.to);
}
method = getMethod(env, clazz, "setSymbol", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.symbol));
}
method = getMethod(env, clazz, "setDescription", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.description));
}
method = getMethod(env, clazz, "setEnable", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.enable);
}
method = getMethod(env, clazz, "setReserved", "([I)V");
if (NULL != method) {
jintArray reserveds = env->NewIntArray(13);
env->SetIntArrayRegion(reserveds, 0, 13, reinterpret_cast<jint*>(tr.reserved));
env->CallVoidMethod(record, method, reserveds);
}
return record;
}
/*
* Symbol session
*/
jobject getConSession(JNIEnv* env, jclass clazz, ConSession tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setOpen_hour", "(S)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.open_hour);
}
method = getMethod(env, clazz, "setOpen_min", "(S)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.open_min);
}
method = getMethod(env, clazz, "setClose_hour", "(S)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.close_hour);
}
method = getMethod(env, clazz, "setClose_min", "(S)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.close_min);
}
method = getMethod(env, clazz, "setOpen", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.open);
}
method = getMethod(env, clazz, "setClose", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.close);
}
/*method = getMethod(env, clazz, "setAlign", "([S)V");
if (NULL != method) {
jshortArray reserveds = env->NewShortArray(7);
env->SetShortArrayRegion(reserveds, 0, 7, reinterpret_cast<jshort*>(tr.align));
env->CallVoidMethod(record, method, reserveds);
}*/
return record;
}
/*
* 获取symbol sessions
*/
jobject getConSessions(JNIEnv* env, jclass clazz, ConSessions tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setQuote", "([Lcom/metoo/mt4/bean/symbol/ConSession;)V");
if (NULL != method) {
ConSession* pquote = tr.quote;
if (NULL != pquote) {
jclass _clazz = env->FindClass("com/metoo/mt4/bean/symbol/ConSession");
if (_clazz == NULL) {
printf("clazz create [com/metoo/mt4/bean/symbol/ConSession] error");
}
else {
int size = 3;
jobjectArray _arr = env->NewObjectArray(size, _clazz, NULL);
for (int i = 0; i < size; i++) {
ConSession _tr = pquote[i];
jobject _record = getConSession(env, _clazz, _tr);
env->SetObjectArrayElement(_arr, i, _record);
}
env->CallVoidMethod(record, method, _arr);
}
}
}
method = getMethod(env, clazz, "setTrade", "([Lcom/metoo/mt4/bean/symbol/ConSession;)V");
if (NULL != method) {
ConSession* ptrade = tr.trade;
if (NULL != ptrade) {
jclass _clazz = env->FindClass("com/metoo/mt4/bean/symbol/ConSession");
if (_clazz == NULL) {
printf("clazz create [com/metoo/mt4/bean/symbol/ConSession] error");
}
else {
int size = 3;
jobjectArray _arr = env->NewObjectArray(size, _clazz, NULL);
for (int i = 0; i < size; i++) {
ConSession _tr = ptrade[i];
jobject _record = getConSession(env, _clazz, _tr);
env->SetObjectArrayElement(_arr, i, _record);
}
env->CallVoidMethod(record, method, _arr);
}
}
}
method = getMethod(env, clazz, "setQuote_overnight", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.quote_overnight);
}
method = getMethod(env, clazz, "setTrade_overnight", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.trade_overnight);
}
/*method = getMethod(env, clazz, "setReserved", "([I)V");
if (NULL != method) {
jintArray reserveds = env->NewIntArray(2);
env->SetIntArrayRegion(reserveds, 0, 2, reinterpret_cast<jint*>(tr.reserved));
env->CallVoidMethod(record, method, reserveds);
}*/
return record;
}
/*
* 获取品种对
*/
jobject getConSymbol(JNIEnv* env, jclass clazz, ConSymbol tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setSymbol", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.symbol));
}
method = getMethod(env, clazz, "setDescription", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.description));
}
method = getMethod(env, clazz, "setSource", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.source));
}
method = getMethod(env, clazz, "setCurrency", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.currency));
}
method = getMethod(env, clazz, "setType", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.type);
}
method = getMethod(env, clazz, "setDigits", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.digits);
}
method = getMethod(env, clazz, "setTrade", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.trade);
}
method = getMethod(env, clazz, "setBackground_color", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.background_color);
}
method = getMethod(env, clazz, "setCount", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.count);
}
method = getMethod(env, clazz, "setCount_original", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.count_original);
}
/*method = getMethod(env, clazz, "setExternal_unused", "([I)V");
if (NULL != method) {
jintArray external_unuseds = env->NewIntArray(7);
env->SetIntArrayRegion(external_unuseds, 0, 7, reinterpret_cast<jint*>(tr.external_unused));
env->CallVoidMethod(record, method, external_unuseds);
}*/
method = getMethod(env, clazz, "setRealtime", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.realtime);
}
method = getMethod(env, clazz, "setStarting", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.starting);
}
method = getMethod(env, clazz, "setExpiration", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.expiration);
}
method = getMethod(env, clazz, "setSessions", "([Lcom/metoo/mt4/bean/symbol/ConSessions;)V");
if (NULL != method) {
ConSessions* psessions = tr.sessions;
if (NULL != psessions) {
jclass _clazz = env->FindClass("com/metoo/mt4/bean/symbol/ConSessions");
if (_clazz == NULL) {
printf("clazz create [com/metoo/mt4/bean/symbol/ConSessions] error");
}
else {
int size = 7;
jobjectArray _arr = env->NewObjectArray(size, _clazz, NULL);
for (int i = 0; i < size; i++) {
ConSessions _tr = psessions[i];
jobject _record = getConSessions(env, _clazz, _tr);
env->SetObjectArrayElement(_arr, i, _record);
}
env->CallVoidMethod(record, method, _arr);
}
}
}
method = getMethod(env, clazz, "setProfit_mode", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.profit_mode);
}
method = getMethod(env, clazz, "setProfit_reserved", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.profit_reserved);
}
method = getMethod(env, clazz, "setFilter", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.filter);
}
method = getMethod(env, clazz, "setFilter_counter", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.filter_counter);
}
method = getMethod(env, clazz, "setFilter_limit", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.filter_limit);
}
method = getMethod(env, clazz, "setFilter_smoothing", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.filter_smoothing);
}
method = getMethod(env, clazz, "setFilter_reserved", "(F)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.filter_reserved);
}
method = getMethod(env, clazz, "setLogging", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.logging);
}
method = getMethod(env, clazz, "setSpread", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.spread);
}
method = getMethod(env, clazz, "setSpread_balance", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.spread_balance);
}
method = getMethod(env, clazz, "setExemode", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.exemode);
}
method = getMethod(env, clazz, "setSwap_enable", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_enable);
}
method = getMethod(env, clazz, "setSwap_type", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_type);
}
method = getMethod(env, clazz, "setSwap_long", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_long);
}
method = getMethod(env, clazz, "setSwap_short", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_short);
}
method = getMethod(env, clazz, "setSwap_rollover3days", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_rollover3days);
}
method = getMethod(env, clazz, "setContract_size", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.contract_size);
}
method = getMethod(env, clazz, "setTick_value", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.tick_value);
}
method = getMethod(env, clazz, "setTick_size", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.tick_size);
}
method = getMethod(env, clazz, "setStops_level", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.stops_level);
}
method = getMethod(env, clazz, "setGtc_pendings", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.gtc_pendings);
}
method = getMethod(env, clazz, "setMargin_mode", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_mode);
}
method = getMethod(env, clazz, "setMargin_initial", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_initial);
}
method = getMethod(env, clazz, "setMargin_maintenance", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_maintenance);
}
method = getMethod(env, clazz, "setMargin_hedged", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_hedged);
}
method = getMethod(env, clazz, "setMargin_divider", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_divider);
}
method = getMethod(env, clazz, "setPoint", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.point);
}
method = getMethod(env, clazz, "setMultiply", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.multiply);
}
method = getMethod(env, clazz, "setBid_tickvalue", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.bid_tickvalue);
}
method = getMethod(env, clazz, "setAsk_tickvalue", "(D)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.ask_tickvalue);
}
method = getMethod(env, clazz, "setLong_only", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.long_only);
}
method = getMethod(env, clazz, "setInstant_max_volume", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.instant_max_volume);
}
method = getMethod(env, clazz, "setMargin_currency", "(Ljava/lang/String;)V");
if (NULL != method) {
env->CallVoidMethod(record, method, env->NewStringUTF(tr.margin_currency));
}
method = getMethod(env, clazz, "setFreeze_level", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.freeze_level);
}
method = getMethod(env, clazz, "setMargin_hedged_strong", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.margin_hedged_strong);
}
method = getMethod(env, clazz, "setValue_date", "(J)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.value_date);
}
method = getMethod(env, clazz, "setQuotes_delay", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.quotes_delay);
}
method = getMethod(env, clazz, "setSwap_openprice", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_openprice);
}
method = getMethod(env, clazz, "setSwap_variation_margin", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.swap_variation_margin);
}
/*method = getMethod(env, clazz, "setUnused", "([I)V");
if (NULL != method) {
jintArray unuseds = env->NewIntArray(21);
env->SetIntArrayRegion(unuseds, 0, 21, reinterpret_cast<jint*>(tr.unused));
env->CallVoidMethod(record, method, unuseds);
}*/
return record;
}
/*
* Security group configuration for client group
*/
jobject getConGroupSec(JNIEnv* env, jclass clazz, ConGroupSec tr) {
jmethodID cid = env->GetMethodID(clazz, "<init>", "()V");
jobject record = env->NewObject(clazz, cid);
jmethodID method = getMethod(env, clazz, "setShow", "(I)V");
if (NULL != method) {
env->CallVoidMethod(record, method, tr.show);
}
method