Exemplo n.º 1
0
void DataWriter::makeDataFileName(int serial, stdString &name)
{
    int  len;
    char buffer[30];    

    if (data_file_name_base.length() > 0)
    {
	name = data_file_name_base;
        if (serial > 0)
        {
            len = snprintf(buffer, sizeof(buffer), "-%d", serial);
            if (len >= (int)sizeof(buffer))
                len = sizeof(buffer)-1;
            name.append(buffer, len);
        }
        return;
    }
    // Else: Create name based on  "<today>[-serial]"
    int year, month, day, hour, min, sec;
    unsigned long nano;
    epicsTime now = epicsTime::getCurrent();    
    epicsTime2vals(now, year, month, day, hour, min, sec, nano);
    if (serial > 0)
        len = snprintf(buffer, sizeof(buffer),
                       "%04d%02d%02d-%d", year, month, day, serial);
    else
        len = snprintf(buffer,sizeof(buffer),
                       "%04d%02d%02d", year, month, day);
    if (len >= (int)sizeof(buffer))
        len = sizeof(buffer)-1;
    name.assign(buffer, len);
}
Exemplo n.º 2
0
void CtrlInfo::getState(size_t state, stdString &result) const
{
    size_t len;
    const char *text = getState(state, len);
    if (text)
    {
        result.assign(text, len);
        return;
    }

    char buffer[80];
    sprintf(buffer, "<Undef: %u>", (unsigned int)state);
    result = buffer;
}
bool ArchiveDataClient::getInfo(int &version,
                                stdString &description,
                                stdVector<stdString> &how_strings,
                                stdVector<stdString> &stat_strings,
                                stdVector<SeverityInfo> &sevr_infos)
{
    xmlrpc_value *result, *hows, *stats, *sevrs, *element;
    xmlrpc_int32 num;
    xmlrpc_bool has_value, txt_stat;
    const char   *str;
    size_t       count, len, i;
    result = xmlrpc_client_call(&env, (char *)URL, "archiver.info", "()");
    if (log_fault())
        return false;
    xmlrpc_parse_value(&env, result, "{s:i,s:s#,s:A,s:A,s:A,*}",
                       "ver",  &num,
                       "desc", &str, &len,
                       "how",  &hows,
                       "stat", &stats,
                       "sevr", &sevrs);
    if (log_fault())
        return false;
    version = num;
    description.assign(str, len);
    // 'how' array
    count = xmlrpc_array_size(&env, hows);
    how_strings.reserve(count);
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, hows, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "s", &str);
        if (log_fault())
            return false;
        how_strings.push_back(stdString(str));
    }
    // 'stat' array
    count = xmlrpc_array_size(&env, stats);
    stat_strings.reserve(count);
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, stats, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "s", &str);
        if (log_fault())
            return false;
        stat_strings.push_back(stdString(str));
    }
    // 'sevr' array
    count = xmlrpc_array_size(&env, sevrs);
    stat_strings.reserve(count);
    SeverityInfo info;
    for (i=0; i<count; ++i)
    {
        element = xmlrpc_array_get_item(&env, sevrs, i);
        if (log_fault())
            return false;
        xmlrpc_parse_value(&env, element, "{s:i,s:s#,s:b,s:b,*}",
                           "num",  &num,
                           "sevr", &str, &len,
                           "has_value",  &has_value,
                           "txt_stat", &txt_stat);
        if (log_fault())
            return false;
        info.num = num;
        info.text.assign(str, len);
        info.has_value = has_value;
        info.txt_stat = txt_stat;
        sevr_infos.push_back(info);
    }
    xmlrpc_DECREF(result);
    return true;
}