Skip to content

Instantly share code, notes, and snippets.

@diegopso
Last active July 1, 2022 16:57
Show Gist options
  • Save diegopso/4323f11341f069a23798ef9662b297b3 to your computer and use it in GitHub Desktop.
Save diegopso/4323f11341f069a23798ef9662b297b3 to your computer and use it in GitHub Desktop.
Static variable in module sample Omnet++
#include "SessionManager.h"
using namespace sdicn;
Define_Module(sdicn::SessionManager);
int SessionManager::binderCounter = 0;
vector<SessionManager::SessionBinding> SessionManager::bindings = vector<SessionBinding>();
void SessionManager::initialize()
{
if (binderCounter == 0) {
bindings = vector<SessionBinding>();
}
++binderCounter;
}
SessionManager::~SessionManager()
{
--binderCounter;
}
#pragma once
#include <tuple>
using namespace std;
#include <omnetpp.h>
using namespace omnetpp;
namespace sdicn {
class SessionManager : public cSimpleModule {
protected:
typedef tuple<string, unsigned, int> SessionBinding; // serviceName, consumerIp, bsIndex
static int binderCounter;
static vector<SessionBinding> bindings;
virtual void initialize() override;
virtual ~SessionManager();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment