coral
A C++ library for distributed co-simulation
importer.hpp
Go to the documentation of this file.
1 
10 #ifndef CORAL_FMI_IMPORTER_HPP
11 #define CORAL_FMI_IMPORTER_HPP
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 
17 #include <boost/filesystem.hpp>
18 
19 #include <coral/config.h>
21 
22 
23 // Forward declarations to avoid external dependency on FMI Library.
24 struct fmi_xml_context_t;
25 typedef fmi_xml_context_t fmi_import_context_t;
26 struct jm_callbacks;
27 
28 
29 namespace coral
30 {
31 namespace fmi
32 {
33 
34 class FMU;
35 
36 
56 class Importer : public std::enable_shared_from_this<Importer>
57 {
58 public:
69  const boost::filesystem::path& cachePath);
70 
79 
80 private:
81  // Private constructors, to force use of factory functions.
82  Importer(const boost::filesystem::path& cachePath);
84 
85 public:
100  std::shared_ptr<FMU> Import(const boost::filesystem::path& fmuPath);
101 
115  const boost::filesystem::path& unpackedFMUPath);
116 
123  void CleanCache();
124 
127 
129  fmi_import_context_t* FmilibHandle() const;
130 
131 private:
132  void PrunePtrCaches();
133 
134  // Note: The order of these declarations is important!
135  std::unique_ptr<coral::util::TempDir> m_tempCacheDir; // Only used when no cache dir is given
136  std::unique_ptr<jm_callbacks> m_callbacks;
138 
139  boost::filesystem::path m_fmuDir;
140  boost::filesystem::path m_workDir;
141 
144 };
145 
146 
147 }} // namespace
148 #endif // header guard
void CleanCache()
Removes unused files and directories from the FMU cache.
An RAII object that creates a unique directory on construction and recursively deletes it again on de...
Definition: filesystem.hpp:27
std::shared_ptr< FMU > ImportUnpacked(const boost::filesystem::path &unpackedFMUPath)
Imports and loads an FMU that has already been unpacked.
STL class.
static std::shared_ptr< Importer > Create()
Creates a new FMU importer that uses a temporary cache directory.
STL class.
fmi_import_context_t * FmilibHandle() const
Returns a pointer to the underlying FMI Library import context.
Imports and caches FMUs.
Definition: importer.hpp:56
std::string LastErrorMessage()
Returns the last FMI Library error message.
Definition: variable_io.hpp:28
Filesystem utilities.
std::shared_ptr< FMU > Import(const boost::filesystem::path &fmuPath)
Imports and loads an FMU.