void UtilAll::init_factory_property()

in src/main/cpp/sdk/common/UtilAll.cpp [44:133]


void UtilAll::init_factory_property(const ons::ONSFactoryProperty &factoryProperty, factory_property &fp,
                                    bool is_producer) {
    memset(&fp, 0, sizeof(factory_property));
    string groupID(factoryProperty.getGroupId());
    if (!groupID.empty()) {
        fp.group_id = const_cast<char *>(factoryProperty.getGroupId());
    } else {
        if (is_producer) {
            fp.group_id = const_cast<char *>(factoryProperty.getProducerId());

        } else {
            fp.group_id = const_cast<char *>(factoryProperty.getConsumerId());

        }
    }
    fp.access_key = const_cast<char *>(factoryProperty.getAccessKey());
    fp.access_secret = const_cast<char *>(factoryProperty.getSecretKey());
    string domain(factoryProperty.getNameSrvDomain());
    if (!domain.empty()) {
        fp.use_domain = 1;
        fp.name_srv_domain = const_cast<char *>(factoryProperty.getNameSrvDomain());
    } else {
        fp.use_domain = 0;
        fp.name_srv_addr = const_cast<char *>(factoryProperty.getNameSrvAddr());
    }
    fp.message_model = const_cast<char *>(factoryProperty.getMessageModel());
    fp.consumer_instance_name = const_cast<char *>(factoryProperty.getConsumerInstanceName());

    string send_msg_timeout_millis = to_string(factoryProperty.getSendMsgTimeout());
    char *send_msg_timeout_millis_ = new char[send_msg_timeout_millis.length() + 1];
    strcpy(send_msg_timeout_millis_, send_msg_timeout_millis.c_str());
    fp.send_msg_timeout_millis = send_msg_timeout_millis_;

    string suspend_time_millis = to_string(factoryProperty.getSuspendTimeMillis());
    char *suspend_time_millis_ = new char[suspend_time_millis.length() + 1];
    strcpy(suspend_time_millis_, suspend_time_millis.c_str());
    fp.suspend_time_millis = suspend_time_millis_;

    string consume_thread_nums = to_string(factoryProperty.getConsumeThreadNums());
    char *consume_thread_nums_ = new char[consume_thread_nums.length() + 1];
    strcpy(consume_thread_nums_, consume_thread_nums.c_str());
    fp.consume_thread_nums = consume_thread_nums_;

    string ons_channel;
    switch (factoryProperty.getOnsChannel()) {
        case ALIYUN:
            ons_channel = "ALIYUN";
            break;
        case CLOUD:
        case ALL:
        case LOCAL:
        case INNER:
            ons_channel = "CLOUD";
            break;
        default:
            ons_channel = "ALIYUN";
            break;
    }
    char *ons_channel_ = new char[ons_channel.length() + 1];
    strcpy(ons_channel_, ons_channel.c_str());
    fp.ons_channel = ons_channel_;

    string max_msg_cache_size = to_string(factoryProperty.getMaxMsgCacheSize());
    char *max_msg_cache_size_ = new char[max_msg_cache_size.length() + 1];
    strcpy(max_msg_cache_size_, max_msg_cache_size.c_str());
    fp.max_msg_cache_size = max_msg_cache_size_;

    string max_msg_cache_size_in_mib = to_string(factoryProperty.getMaxMsgCacheSizeInMiB());
    char *max_msg_cache_size_in_mib_ = new char[max_msg_cache_size_in_mib.length() + 1];
    strcpy(max_msg_cache_size_in_mib_, max_msg_cache_size_in_mib.c_str());
    fp.max_msg_cache_size_in_mb = max_msg_cache_size_in_mib_;

    string ons_trace_switch = "true";
    if (!factoryProperty.getOnsTraceSwitch()) {
        ons_trace_switch = "false";
    }
    char *ons_trace_switch_ = new char[ons_trace_switch.length() + 1];
    strcpy(ons_trace_switch_, ons_trace_switch.c_str());
    fp.ons_trace_switch = ons_trace_switch_;

    string language_identifier = "1";
    char *language_identifier_ = new char[language_identifier.length() + 1];
    strcpy(language_identifier_, language_identifier.c_str());
    fp.language_identifier = language_identifier_;

    string instance_id = to_string(factoryProperty.getInstanceId());
    char *instance_id_ = new char[instance_id.length() + 1];
    strcpy(instance_id_, instance_id.c_str());
    fp.instance_id = instance_id_;
}