#include <boost/algorithm/string.hpp>
#include <ctype.h>
#include <errno.h>
-#include <fstream>
-#include <queue>
-#include <unordered_map>
#include <wchar.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(replay,xbt,"Replay trace reader");
-xbt_dict_t xbt_action_queues = nullptr;
-bool is_replay_active = false;
-
namespace simgrid {
namespace xbt {
std::ifstream* action_fs = nullptr;
std::unordered_map<std::string, action_fun> action_funs;
-typedef std::vector<std::string> ReplayAction;
static void read_and_trim_line(std::ifstream* fs, std::string* line)
{
}
}
-void replay_init()
-{
- if (!is_replay_active) {
- xbt_action_queues = xbt_dict_new_homogeneous(nullptr);
- is_replay_active = true;
- }
-}
-
-void replay_exit()
-{
- xbt_dict_free(&xbt_action_queues);
- xbt_action_queues = nullptr;
-}
-
-bool replay_is_active()
-{
- return is_replay_active;
-}
-
static ReplayAction* get_action(char* name)
{
ReplayAction* action;
- std::queue<ReplayAction*>* myqueue = (std::queue<ReplayAction*>*)xbt_dict_get_or_null(xbt_action_queues, name);
+ std::queue<ReplayAction*>* myqueue = nullptr;
+ if (action_queues.find(std::string(name)) != action_queues.end())
+ myqueue = action_queues.at(std::string(name));
if (myqueue == nullptr || myqueue->empty()) { // Nothing stored for me. Read the file further
if (action_fs == nullptr) { // File closed now. There's nothing more to read. I'm out of here
goto todo_done;
return action;
} else {
// Else, I have to store it for the relevant colleague
- std::queue<ReplayAction*>* otherqueue =
- (std::queue<ReplayAction*>*)xbt_dict_get_or_null(xbt_action_queues, evtname.c_str());
+ std::queue<ReplayAction*>* otherqueue = nullptr;
+ if (action_queues.find(evtname) != action_queues.end())
+ otherqueue = action_queues.at(evtname);
if (otherqueue == nullptr) { // Damn. Create the queue of that guy
otherqueue = new std::queue<ReplayAction*>();
- xbt_dict_set(xbt_action_queues, evtname.c_str(), otherqueue, nullptr);
+ action_queues.insert({evtname, otherqueue});
}
otherqueue->push(action);
}
todo_done:
if (myqueue != nullptr) {
delete myqueue;
- xbt_dict_remove(xbt_action_queues, name);
+ action_queues.erase(std::string(name));
}
return nullptr;
}
*/
void xbt_replay_action_register(const char* action_name, action_fun function)
{
- if (!is_replay_active) // If the user registers a function before the start
- simgrid::xbt::replay_init();
simgrid::xbt::action_funs.insert({std::string(action_name), function});
}