Пример #1
0
void ConfigEndpoint::load(std::string configname){
    this->configname = configname;
    std::ifstream file_stream;
    file_stream.open(configname.c_str());
    //TODO: parsen und einfügen
    std::string line;
    while(std::getline(file_stream,line)){
        if(line.find('#')!=std::string::npos){
            try {
                Command_ptr command(new Command(line, this->shared_from_this()));
                {
                    boost::mutex::scoped_lock lock(commandsMutex);
                    commands.push_back(command);
                }
            }
            catch (const std::invalid_argument& ia) {
                std::ostringstream oss;
                oss << "Found a command that might not be conform with command format: " << line;
                log(oss.str());
            }
        }
    }
    file_stream.close();
    registerEndpoint();
    {
        boost::mutex::scoped_lock lock(commandsMutex);
        for (std::list<Command_ptr>::const_iterator command = commands.begin(), end = commands.end(); command != end; ++command)
        {
            deliver(*command);
        }
    }
 }
Пример #2
0
void NMEAEndpoint::add_midpoint_cmd(Command_ptr command){
    try{
        NMEAMidpoint_ptr midpoint = NMEAMidpoint::factory(getConnectedTo(),command->getArguments());
        unregisterEndpoint();
        setConnectedTo(midpoint);
        registerEndpoint();
        
        command->answer("Midpoint created and connected.", shared_from_this());
    }
    catch(std::exception& e){
        command->answer(Answer::WRONG_ARGS, "Cannot understand "+command->getArguments()+" for command "+command->getCommand()+". Not a midpoint class\n", shared_from_this());
    }
}
Пример #3
0
void FileEndpoint::initialize(){
    NMEAEndpoint::initialize();
    registerIntCmd("min_available","Minimimum remaining disk space", "Defines the minimum remaining disk space that should be left. When there is not enough space on the disk hosting this file, nothing is written. 0 = nocheck", &min_available_mbs, 0, 0, std::numeric_limits<int>::max(), true);
    boost::function<void (Command_ptr)> func = boost::bind(&FileEndpoint::space_left_cmd, this, _1);
    registerVoidCmd("space_left","Print Space left", "Prints the space left on the disk",  func);
    func = boost::bind(&FileEndpoint::seek_cmd, this, _1);
    registerVoidCmd("seek","Seek position in log", "Put playback position at time.",  func);
    registerBoolCmd("record_answer","Record answers", "When on, answers are recorded to the file aswell.",  &record_answers, false, true);
    registerStringCmd("timestamp_format", "Format of the timestamp for messages", "Defines how the timestamp in front of each message is formated. Default is: \"%Y-%m-%d %H:%M:%s\" ", &timestamp_format, "%Y-%m-%d %H:%M:%s ", true);
    registerUIntCmd("speedup","Speedup factor for playback", "Defines the factor for speedup of playback", &speedup, 1, 1, 1000, true);
    
    registerEndpoint();
}
Пример #4
0
template<class T> void AsyncEndpoint<T>::start()
{
    registerEndpoint();
    if(boost::shared_ptr<AsyncEndpoint<T> > activated = activateSession(this->shared_from_this())){
        //Transfer session object over to old session
        activated->unregisterEndpoint();
        {
            boost::mutex::scoped_lock lock(message_queueMutex);
            message_queue = std::deque<Message_ptr>(activated->message_queue);
        }
        log("Session reactivated");
    }
    boost::system::error_code ec(0,boost::system::system_category());
    handle_write(ec);
    isActive=true;
    aostream->async_read_some(boost::asio::buffer(data_, max_length),
                              boost::bind(&AsyncEndpoint::handle_read, this,
                                          boost::asio::placeholders::error,
                                          boost::asio::placeholders::bytes_transferred));
}//  NMEA-Protocol-Server