Commit | Line | Data |
---|---|---|
d44e3c4f | 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 | * Kovacs, Ferenc | |
11 | * Raduly, Csaba | |
12 | * Zalanyi, Balazs Andor | |
13 | * Pandi, Krisztian | |
14 | * | |
15 | ******************************************************************************/ | |
970ed795 EL |
16 | #include "LoggerPlugin.hh" |
17 | ||
18 | #include "../common/memory.h" | |
19 | ||
20 | #include "TitanLoggerApi.hh" | |
21 | #include "Error.hh" | |
22 | #include "Logger.hh" | |
23 | #include "ILoggerPlugin.hh" | |
24 | ||
25 | #include <assert.h> | |
26 | ||
27 | // constructor for dynamic plug-in | |
28 | LoggerPlugin::LoggerPlugin(const char *path) : | |
29 | ref_(NULL), handle_(NULL), filename_(NULL), create_(NULL), | |
30 | is_log2str_capable_(false) | |
31 | { | |
32 | assert(path != NULL); | |
33 | this->filename_ = mcopystr(path); | |
34 | } | |
35 | ||
36 | // constructor for static plug-in | |
37 | // Rant. The logical thing would be for the type of the parameter to be | |
38 | // cb_create_plugin (which is already a pointer). But calling | |
39 | // LoggerPlugin(create_legacy_logger) results in the wrong value being passed | |
40 | // to the function. So the call has to be written as | |
41 | // LoggerPlugin(&create_legacy_logger), which means that the type | |
42 | // of the parameter has to be _pointer_to_ cb_create_plugin. | |
43 | LoggerPlugin::LoggerPlugin(cb_create_plugin *create) : | |
44 | ref_(NULL), handle_(NULL), filename_(NULL), | |
45 | // We want the create_ member to be cb_create_plugin, to be able to call | |
46 | // this->create_(). Hence the need for this hideous cast. | |
47 | create_((cb_create_plugin)(unsigned long)create), | |
48 | is_log2str_capable_(false) | |
49 | { | |
50 | } | |
51 | ||
52 | LoggerPlugin::~LoggerPlugin() | |
53 | { | |
54 | Free(this->filename_); | |
55 | } | |
56 | ||
57 | //void LoggerPlugin::load() | |
58 | ||
59 | //void LoggerPlugin::unload() | |
60 | ||
61 | void LoggerPlugin::reset() | |
62 | { | |
63 | this->ref_->reset(); | |
64 | } | |
65 | ||
66 | void LoggerPlugin::open_file(bool is_first) | |
67 | { | |
68 | this->ref_->open_file(is_first); | |
69 | } | |
70 | ||
71 | void LoggerPlugin::close_file() | |
72 | { | |
73 | this->ref_->close_file(); | |
74 | } | |
75 | ||
76 | void LoggerPlugin::set_file_name(const char *new_filename_skeleton, | |
77 | bool from_config) | |
78 | { | |
79 | this->ref_->set_file_name(new_filename_skeleton, from_config); | |
80 | } | |
81 | ||
82 | void LoggerPlugin::set_append_file(bool new_append_file) | |
83 | { | |
84 | this->ref_->set_append_file(new_append_file); | |
85 | } | |
86 | ||
87 | bool LoggerPlugin::set_file_size(int p_size) | |
88 | { | |
89 | return this->ref_->set_file_size(p_size); | |
90 | } | |
91 | ||
92 | bool LoggerPlugin::set_file_number(int p_number) | |
93 | { | |
94 | return this->ref_->set_file_number(p_number); | |
95 | } | |
96 | ||
97 | bool LoggerPlugin::set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action) | |
98 | { | |
99 | return this->ref_->set_disk_full_action(p_disk_full_action); | |
100 | } | |
101 | ||
102 | void LoggerPlugin::set_parameter(const char* param_name, const char* param_value) | |
103 | { | |
104 | this->ref_->set_parameter(param_name, param_value); | |
105 | } | |
106 | ||
107 | int LoggerPlugin::log(const TitanLoggerApi::TitanLogEvent& event, | |
108 | bool log_buffered, bool separate_file, bool use_emergency_mask) | |
109 | { | |
110 | if (!this->ref_) return 1; | |
111 | this->ref_->log(event, log_buffered, separate_file, use_emergency_mask); | |
112 | return 0; | |
113 | } | |
114 | ||
115 | CHARSTRING LoggerPlugin::log2str(const TitanLoggerApi::TitanLogEvent& event) const | |
116 | { | |
117 | assert(this->ref_); | |
118 | if (!this->is_log2str_capable_) return CHARSTRING(); | |
119 | return this->ref_->log2str(event); | |
120 | } | |
121 | ||
122 | const char *LoggerPlugin::plugin_name() const | |
123 | { | |
124 | assert(this->ref_); | |
125 | return this->ref_->plugin_name(); | |
126 | } | |
127 | ||
128 | bool LoggerPlugin::is_configured() const | |
129 | { | |
130 | return this->ref_ != NULL && this->ref_->is_configured(); | |
131 | } | |
132 | ||
133 | void LoggerPlugin::set_configured(bool configured) | |
134 | { | |
135 | if (this->ref_ != NULL) | |
136 | this->ref_->set_configured(configured); | |
137 | } |