| 1 | /****************************************************************************** |
| 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * Balasko, Jeno |
| 10 | * Delic, Adam |
| 11 | * |
| 12 | ******************************************************************************/ |
| 13 | #ifndef TSTLogger_HH |
| 14 | #define TSTLogger_HH |
| 15 | |
| 16 | #include <string> |
| 17 | #include <map> |
| 18 | |
| 19 | namespace TitanLoggerApi |
| 20 | { |
| 21 | class TitanLogEvent; |
| 22 | class TimestampType; |
| 23 | class QualifiedName; |
| 24 | class TestcaseType; |
| 25 | class VerdictOp; |
| 26 | } |
| 27 | |
| 28 | class ILoggerPlugin; |
| 29 | |
| 30 | struct ParameterData |
| 31 | { |
| 32 | std::string default_value; |
| 33 | bool optional; |
| 34 | std::string description; |
| 35 | bool set; |
| 36 | std::string value; |
| 37 | ParameterData(): optional(false), set(false) {} |
| 38 | ParameterData(const std::string& def_val, const bool opt=true, const std::string& descr=""): |
| 39 | default_value(def_val), optional(opt), description(descr), set(false) {} |
| 40 | void set_value(std::string v) { set=true; value=v; } |
| 41 | std::string get_value() { return set ? value : default_value; } |
| 42 | }; |
| 43 | |
| 44 | class TSTLogger: public ILoggerPlugin |
| 45 | { |
| 46 | public: |
| 47 | explicit TSTLogger(); |
| 48 | virtual ~TSTLogger(); |
| 49 | inline bool is_static() { return false; } |
| 50 | void init(const char *options = NULL); |
| 51 | void fini(); |
| 52 | |
| 53 | void log(const TitanLoggerApi::TitanLogEvent& event, bool log_buffered); |
| 54 | void log(const TitanLoggerApi::TitanLogEvent& event, bool log_buffered, bool separate_file, bool use_emergency_mask); |
| 55 | void set_parameter(const char *parameter_name, const char *parameter_value); |
| 56 | |
| 57 | private: |
| 58 | std::string user_agent; // HTTP req. parameter value |
| 59 | std::map<std::string,ParameterData> parameters; // plugin parameters |
| 60 | |
| 61 | std::string suite_id_; |
| 62 | std::string tcase_id_; |
| 63 | int testcase_count_; |
| 64 | |
| 65 | explicit TSTLogger(const TSTLogger&); |
| 66 | TSTLogger& operator=(const TSTLogger&); |
| 67 | |
| 68 | bool log_plugin_debug(); |
| 69 | |
| 70 | static std::string get_tst_time_str(const TitanLoggerApi::TimestampType& timestamp); |
| 71 | static std::string get_host_name(); |
| 72 | static std::string get_user_name(); |
| 73 | |
| 74 | void add_database_params(std::map<std::string,std::string>& req_params); |
| 75 | std::string post_message(std::map<std::string,std::string> req_params, const std::string& TST_service_uri); |
| 76 | |
| 77 | bool is_main_proc() const; |
| 78 | |
| 79 | void log_testcase_start(const TitanLoggerApi::QualifiedName& testcaseStarted, const TitanLoggerApi::TimestampType& timestamp); |
| 80 | void log_testcase_stop(const TitanLoggerApi::TestcaseType& testcaseFinished, const TitanLoggerApi::TimestampType& timestamp); |
| 81 | void log_testsuite_stop(const TitanLoggerApi::TimestampType& timestamp); |
| 82 | void log_testsuite_start(const TitanLoggerApi::TimestampType& timestamp); |
| 83 | void log_verdictop_reason(const TitanLoggerApi::VerdictOp& verdictOp); |
| 84 | }; |
| 85 | |
| 86 | #endif // TSTLogger_HH |