Skip to content

Commit

Permalink
Added Container management methods to Manager class
Browse files Browse the repository at this point in the history
  • Loading branch information
timschwartz committed Feb 18, 2019
1 parent b917843 commit 0e09dbe
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 676 deletions.
675 changes: 4 additions & 671 deletions COPYING

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"

/* Name of package */
Expand Down
9 changes: 8 additions & 1 deletion include/libecs-cpp/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

namespace ecs
{
class Manager;

class Container
{
public:
Container();
Container(std::string handle);
Container(std::string Handle);
void ManagerSet(ecs::Manager *Manager);
std::string HandleGet();
private:
std::string Handle;
ecs::Manager *Manager = nullptr;
};
}
2 changes: 2 additions & 0 deletions include/libecs-cpp/Manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <vector>
#include <mutex>

namespace ecs
{
Expand All @@ -21,5 +22,6 @@ namespace ecs
void ContainersKill(std::vector<std::string>);
ecs::Container *ContainerCreate(std::string handle);
std::map<std::string, ecs::Container *> containers;
std::mutex mutex_containers;
};
}
34 changes: 34 additions & 0 deletions src/Container.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <uuid/uuid.h>
#include <libecs-cpp/ecs.hpp>

namespace ecs
{
Container::Container()
{
uuid_t uuid;
uuid_generate(uuid);

this->Handle.resize(40);
uuid_unparse(uuid, &this->Handle[0]);

// this->container_thread = std::thread(&container::thread_func, this);
// this->container_thread.detach();
}

Container::Container(std::string Handle)
{
this->Handle = Handle;
// this->ContainerThread = std::thread(&container::thread_func, this);
// this->ContainerThread.detach();
}

void Container::ManagerSet(ecs::Manager *Manager)
{
this->Manager = Manager;
}

std::string Container::HandleGet()
{
return this->Handle;
}
}
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libecs-cpp.la
pkginclude_HEADERS = \
../include/libecs-cpp/ecs.hpp \
../include/libecs-cpp/Manager.hpp
../include/libecs-cpp/Manager.hpp \
../include/libecs-cpp/Container.hpp

libecs_cpp_la_CXXFLAGS = -std=c++17 -I../include $(UUID_CFLAGS)
libecs_cpp_la_LIBADD = -lpthread $(UUID_LIBS)
libecs_cpp_la_SOURCES = Manager.cpp
libecs_cpp_la_SOURCES = Manager.cpp Container.cpp
libecs_cpp_la_LDFLAGS = -no-undefined
58 changes: 58 additions & 0 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,62 @@ namespace ecs
Manager::Manager()
{
}

ecs::Container *Manager::Container(std::string handle)
{
return this->ContainerCreate(handle);
}

ecs::Container *Manager::Container()
{
return this->ContainerCreate("");
}

ecs::Container *Manager::ContainerCreate(std::string handle)
{
ecs::Container *c;
this->mutex_containers.lock();
{
if(handle.size() == 0)
{
c = new ecs::Container();
this->containers[c->HandleGet()] = c;
}
else
{
if(this->containers.count(handle) == 0)
{
c = new ecs::Container(handle);
this->containers[handle] = c;
}
else c = this->containers[handle];
}

c->ManagerSet(this);
}
this->mutex_containers.unlock();
return c;
}

std::vector<std::string> Manager::ContainersGet()
{
std::vector<std::string> handles;

for(auto &c : this->containers)
handles.push_back(c.first);

return handles;
}

void Manager::ContainersKill(std::vector<std::string> handles)
{
this->mutex_containers.lock();
{
for(auto &h : handles)
{
delete this->containers[h];
}
}
this->mutex_containers.unlock();
}
}

0 comments on commit 0e09dbe

Please sign in to comment.