Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (c) 2000-2014 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 | #include "LoggerPlugin.hh" | |
9 | #include "ILoggerPlugin.hh" | |
10 | ||
11 | #include <assert.h> | |
12 | #include <dlfcn.h> | |
13 | ||
14 | void LoggerPlugin::load() | |
15 | { | |
16 | if (this->filename_) { | |
17 | // Dynamic plug-in requires dynamic runtime. Panic. | |
18 | TTCN_Logger::fatal_error("Static runtime cannot load plugins"); | |
19 | } else { | |
20 | // Static plug-in. We simply instantiate the class without any `dl*()'. | |
21 | assert(this->create_); | |
22 | this->ref_ = this->create_(); | |
23 | } | |
24 | ||
25 | this->ref_->init(); | |
26 | this->is_log2str_capable_ = this->ref_->is_log2str_capable(); | |
27 | } | |
28 | ||
29 | // Completely destroy the logger plug-in and make it useless. However, | |
30 | // reloading is possible. This should be called before the logger is | |
31 | // deleted. | |
32 | void LoggerPlugin::unload() | |
33 | { | |
34 | if (!this->ref_) return; | |
35 | this->ref_->fini(); | |
36 | if (this->filename_) { | |
37 | // This cannot happen. | |
38 | TTCN_Logger::fatal_error("Static runtime cannot have plugins"); | |
39 | } else { | |
40 | // For static plug-ins, it's simple. | |
41 | delete this->ref_; | |
42 | this->create_ = NULL; | |
43 | } | |
44 | this->ref_ = NULL; | |
45 | } |