Beispiel #1
0
void StoreServer::handle_read(TcpConnection::Pointer conn, std::size_t bytes_transfered) {
    ConnData& data = conns_[conn];
    std::string& buf = data.buf;
    //没有获得完整命令,就返回
    buf.append(std::string(conn->buf().data(), bytes_transfered));
    if (buf.length() < 3) {
        return;
    }
    std::size_t len = static_cast<std::size_t>(total_len(buf));
    if (buf.length() < len) {
        return;
    }
    std::string cmd = buf.substr(0, len);
    buf.erase(0, len);
    std::string retmsg("");
    //将命令分发到对应的处理函数中,返回结果
    int err = dispath_cmd(cmd, conn, retmsg);
    //发送response
    std::string response("");
    if (err < 0) {
        response = get_response(retmsg, RESP_TYPE_ERR);
    } else {
        response = get_response(retmsg, RESP_TYPE_OK);
        persistence_.record(cmd,  data.db);
    }
    conn->send(response);
    //尾递归,处理没有处理完的命令
    handle_read(conn, 0);
}
void ModelListDialog::OnButton_ExportCsvClick(wxCommandEvent& event)
{
#if 0
    model name
    display as
    type of strings
#strings
#nodes
    start channel
    start node = (channel+2)/3;
    my display
    brightness
#endif // 0
    wxLogNull logNo; //kludge: avoid "error 0" message from wxWidgets after new file is written
    wxString filename = wxFileSelector(_("Choose output file"), wxEmptyString, wxEmptyString, wxEmptyString, "Export files (*.csv)|*.csv", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
//    if (filename.IsEmpty()) retmsg(wxString("Please choose an output file name."));
    if (filename.IsEmpty()) return;

    wxFile f(filename);
//    bool isnew = !wxFile::Exists(filename);
    if (!f.Create(filename, true) || !f.IsOpened()) retmsg(wxString::Format("Unable to create file %s. Error %d\n", filename, f.GetLastError()));
    f.Write(_("Model_name, Display_as, String_type, String_count, Node_count, Start_channel, Start_node, My_display, Brightness+-\n"));

    int first = 0, last = ListBox1->GetCount();
    if (ListBox1->GetSelection() != wxNOT_FOUND) last = 1 + (first = ListBox1->GetSelection());
    for (int i = first; i < last; ++i)
    {
        wxXmlNode* node = (wxXmlNode*)ListBox1->GetClientData(i);
        ModelClass model;
        model.SetFromXml(node);
        wxString stch = node->GetAttribute("StartChannel", wxString::Format("%d?", model.NodeStartChannel(0) + 1)); //NOTE: value coming from model is probably not what is wanted, so show the base ch# instead
        f.Write(wxString::Format("\"%s\", \"%s\", \"%s\", %d, %d, %s, %d, %d, %d\n", model.name, model.GetDisplayAs(), model.GetStringType(), model.GetNodeCount() / model.NodesPerString(), model.GetNodeCount(), stch, /*WRONG:*/ model.NodeStartChannel(0) / model.NodesPerString() + 1, model.MyDisplay, model.ModelBrightness));
//no worky        f.Flush(); //paranoid: write out data in case model loop crashes
    }
    f.Close();
    retmsg(wxString::Format(_("Models exported: %d of %d"), last - first, ListBox1->GetCount()));
}
Beispiel #3
0
std::string CDRTPHelper::GetReturnMsg()
{
	std::string retmsg(m_responsePack.pack.vsmess);
	return retmsg;
}