00001 //--------------------------------------------------------------------------
00002 // Copyright (C) 2014-2017 Cisco and/or its affiliates. All rights reserved.
00003 //
00004 // This program is free software; you can redistribute it and/or modify it
00005 // under the terms of the GNU General Public License Version 2 as published
00006 // by the Free Software Foundation. You may not use, modify or distribute
00007 // this program under any other version of the GNU General Public License.
00008 //
00009 // This program is distributed in the hope that it will be useful, but
00010 // WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program; if not, write to the Free Software Foundation, Inc.,
00016 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017 //--------------------------------------------------------------------------
00018 // analyzer.h author Russ Combs <rucombs@cisco.com>
00019
00020 #ifndef ANALYZER_H
00021 #define ANALYZER_H
00022
00023 // Analyzer provides the packet acquisition and processing loop. Since it
00024 // runs in a different thread, it also provides a command facility so that
00025 // to control the thread and swap configuration.
00026
00027 #include <atomic>
00028 #include <mutex>
00029 #include <queue>
00030 #include <string>
00031
00032 class AnalyzerCommand;
00033 class SFDAQInstance;
00034 class Swapper;
00035
00036 class Analyzer
00037 {
00038 public:
00039 enum class State {
00040 NEW,
00041 INITIALIZED,
00042 STARTED,
00043 RUNNING,
00044 PAUSED,
00045 STOPPED
00046 };
00047 Analyzer(unsigned id, const char* source);
00048
00049 void operator()(Swapper*, uint16_t run_num);
00050
00051 State get_state() { return state; }
00052 const char* get_state_string();
00053 const char* get_source() { return source.c_str(); }
00054
00055 void execute(AnalyzerCommand*);
00056
00057 bool requires_privileged_start() { return privileged_start; }
00058
00059 // Functions called by analyzer commands
00060 void start();
00061 void run(bool paused = false);
00062 void stop();
00063 void pause();
00064 void resume();
00065 void reload_daq();
00066
00067 private:
00068 void analyze();
00069 bool handle_command();
00070 void set_state(State);
00071
00072 public:
00073 std::queue<AnalyzerCommand*> completed_work_queue;
00074 std::mutex completed_work_queue_mutex;
00075 std::queue<AnalyzerCommand*> pending_work_queue;
00076
00077 private:
00078 std::atomic<State> state;
00079 std::atomic<bool> privileged_start;
00080
00081 unsigned id;
00082 bool exit_requested;
00083
00084 std::string source;
00085 SFDAQInstance* daq_instance;
00086
00087 std::mutex pending_work_queue_mutex;
00088 };
00089
00090 #endif
00091
END OF CODE