GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 1 / 2
Functions: 0.0% 0 / 1 / 2
Branches: -% 0 / 1 / 1

src/cli/MeasureManager.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef MEASUREMANAGER_H
7 #define MEASUREMANAGER_H
8
9 #include "../utilities/core/Logger.hpp"
10 #include "../utilities/core/Path.hpp"
11 #include "../scriptengine/ScriptEngine.hpp"
12
13 #include "../model/Model.hpp"
14 #include "../utilities/idf/Workspace.hpp"
15 #include "../measure/OSMeasureInfoGetter.hpp"
16 #include "../utilities/bcl/BCLMeasure.hpp"
17
18 #include <map>
19 #include <memory>
20 #include <string>
21
22 namespace Json {
23 class Value;
24 }
25
26 namespace httplib {
27 class Server;
28 struct Request;
29 struct Response;
30 } // namespace httplib
31
32 namespace openstudio {
33
34 struct OSMInfo
35 {
36 std::string checksum;
37 openstudio::model::Model model;
38 openstudio::Workspace workspace;
39 };
40
41 struct IDFInfo
42 {
43 std::string checksum;
44 openstudio::Workspace workspace;
45 };
46
47 struct BCLMeasureInfo
48 {
49 ✗ explicit BCLMeasureInfo(openstudio::BCLMeasure t_measure) : measure(std::move(t_measure)) {}
50 openstudio::BCLMeasure measure;
51 // Map of osmPath to measureInfo
52 std::map<openstudio::path, openstudio::measure::OSMeasureInfo> measureInfos;
53 };
54
55 class MeasureManager
56 {
57 public:
58 MeasureManager(ScriptEngineInstance& t_rubyEngine, ScriptEngineInstance& t_pythonEngine);
59
60 boost::optional<OSMInfo> getModel(const openstudio::path& osmPath, bool force_reload = false);
61 boost::optional<IDFInfo> getIdf(const openstudio::path& idfPath, bool force_reload = false);
62 boost::optional<BCLMeasure> getMeasure(const openstudio::path& measureDirPath, bool force_reload = false);
63 openstudio::measure::OSMeasureInfo getMeasureInfo(const openstudio::path& measureDirPath, const BCLMeasure& measure,
64 const openstudio::path& osmOrIdfPath = "",
65 const boost::optional<model::Model>& model_ = boost::none,
66 const boost::optional<Workspace>& workspace_ = boost::none);
67
68 // boost::optional<openstudio::measure::OSMeasureInfo> getMeasureInfo(const openstudio::path& measureDirPath, const openstudio::BCLMeasure& measure,
69 // const boost::optional<model::Model>& model,
70 // const boost::optional<Workspace>& workspace);
71
72 // getMeasureInfo;
73 // computeArguments
74 // getMeasureHash;
75 Json::Value internalState() const;
76
77 std::size_t clearMeasureInfoForOsmorIdfPath(const openstudio::path& osmOrIdfPath);
78
79 void reset();
80
81 private:
82 − REGISTER_LOGGER("MeasureManager");
83 //#if USE_RUBY_ENGINE
84 ScriptEngineInstance& rubyEngine;
85 //#endif
86 //#if USE_PYTHON_ENGINE
87 ScriptEngineInstance& pythonEngine;
88 //#endif
89
90 std::map<openstudio::path, OSMInfo> m_osms;
91 std::map<openstudio::path, IDFInfo> m_idfs;
92 std::map<openstudio::path, BCLMeasureInfo> m_measures;
93 };
94
95 class MeasureManagerServer
96 {
97 public:
98 explicit MeasureManagerServer(unsigned port, ScriptEngineInstance& rubyEngine, ScriptEngineInstance& pythonEngine);
99 ~MeasureManagerServer();
100
101 bool open();
102 bool close();
103 void do_tasks_forever();
104
105 protected:
106 private:
107 struct ResponseType
108 {
109 int status_code;
110 std::string body;
111 };
112
113 // Request handlers
114 ResponseType status(const Json::Value& body);
115 ResponseType internal_state(const Json::Value& body);
116 ResponseType reset(const Json::Value& body);
117 ResponseType set(const Json::Value& body);
118 ResponseType download_bcl_measure(const Json::Value& body);
119 ResponseType get_model(const Json::Value& body);
120 ResponseType bcl_measures(const Json::Value& body);
121 ResponseType compute_arguments(const Json::Value& body);
122 ResponseType create_measure(const Json::Value& body);
123 ResponseType duplicate_measure(const Json::Value& body);
124 ResponseType update_measures(const Json::Value& body);
125
126 using memRequestHandlerFunPtr = ResponseType (MeasureManagerServer::*)(const Json::Value& body);
127 void handle_request(const httplib::Request& req, httplib::Response& res, const Json::Value& body, memRequestHandlerFunPtr request_handler);
128
129 void handle_get(const httplib::Request& req, httplib::Response& res);
130 void handle_post(const httplib::Request& req, httplib::Response& res);
131
132 // Helper to return a 404 error
133 static void unknown_endpoint(const httplib::Request& req, httplib::Response& res);
134
135 MeasureManager m_measureManager;
136 std::unique_ptr<httplib::Server> m_server;
137
138 std::string m_url;
139 unsigned m_port;
140 std::string m_host;
141 openstudio::path my_measures_dir;
142 };
143
144 } // namespace openstudio
145
146 #endif // MEASUREMANAGER_H
147