Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define context related globals as static members of Context.
[simgrid.git] / src / kernel / actor / SimcallObserver.hpp
index 5b47b31adba697d1ed4cd79520e8cd6dc43e5d09..71f7e13e6008af98aada272964936174c2d649f9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -11,6 +11,7 @@
 #include "xbt/asserts.h"
 
 #include <string>
+#include <unordered_map>
 
 namespace simgrid::kernel::actor {
 
@@ -125,6 +126,32 @@ public:
   s4u::ActorPtr get_other_actor() const { return other_; }
   double get_timeout() const { return timeout_; }
 };
+
+class ObjectAccessSimcallObserver final : public SimcallObserver {
+  ObjectAccessSimcallItem* const object_;
+
+public:
+  ObjectAccessSimcallObserver(ActorImpl* actor, ObjectAccessSimcallItem* object)
+      : SimcallObserver(actor), object_(object)
+  {
+  }
+  void serialize(std::stringstream& stream) const override;
+  std::string to_string() const override;
+  bool is_visible() const override;
+  bool is_enabled() override { return true; }
+
+  ActorImpl* get_owner() const;
+};
+
+/* Semi private template used by the to_string methods of various observer classes */
+template <typename A> static std::string ptr_to_id(A* ptr)
+{
+  static std::unordered_map<A*, std::string> map;
+  if (map.find(ptr) == map.end())
+    map.insert(std::make_pair(ptr, std::to_string(map.size() + 1)));
+  return map[ptr];
+}
+
 } // namespace simgrid::kernel::actor
 
 #endif