Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make gym interface ns3 singleton #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions model/gym-interface/cpp/ns3-ai-gym-interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ namespace ns3
NS_LOG_COMPONENT_DEFINE("OpenGymInterface");
NS_OBJECT_ENSURE_REGISTERED(OpenGymInterface);

Ptr<OpenGymInterface>
OpenGymInterface::Get()
{
NS_LOG_FUNCTION_NOARGS();
return *DoGet();
}

OpenGymInterface::OpenGymInterface()
: m_simEnd(false),
m_stopEnvRequested(false),
Expand Down Expand Up @@ -364,18 +357,6 @@ OpenGymInterface::SetExecuteActionsCb(Callback<bool, Ptr<OpenGymDataContainer>>
m_actionCb = cb;
}

void
OpenGymInterface::DoInitialize()
{
NS_LOG_FUNCTION(this);
}

void
OpenGymInterface::DoDispose()
{
NS_LOG_FUNCTION(this);
}

void
OpenGymInterface::Notify(Ptr<OpenGymEnv> entity)
{
Expand All @@ -390,11 +371,4 @@ OpenGymInterface::Notify(Ptr<OpenGymEnv> entity)
NotifyCurrentState();
}

Ptr<OpenGymInterface>*
OpenGymInterface::DoGet()
{
static Ptr<OpenGymInterface> ptr = CreateObject<OpenGymInterface>();
return &ptr;
}

} // namespace ns3
9 changes: 1 addition & 8 deletions model/gym-interface/cpp/ns3-ai-gym-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ class OpenGymSpace;
class OpenGymDataContainer;
class OpenGymEnv;

class OpenGymInterface : public Object
class OpenGymInterface : public Singleton<OpenGymInterface>, public Object
{
public:
static Ptr<OpenGymInterface> Get();
OpenGymInterface();
~OpenGymInterface() override;
static TypeId GetTypeId();
Expand Down Expand Up @@ -68,13 +67,7 @@ class OpenGymInterface : public Object

void Notify(Ptr<OpenGymEnv> entity);

protected:
// Inherited
void DoInitialize() override;
void DoDispose() override;

private:
static Ptr<OpenGymInterface>* DoGet();
// static void Delete();

bool m_simEnd;
Expand Down