interface/event

This commit is contained in:
Perttu Ahola 2014-09-17 01:04:51 +03:00
parent c0aa5e950d
commit dd860c461d
6 changed files with 52 additions and 8 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*~ *~
*.old *.old
*.tar.gz *.tar.gz
session.vim
/build /build
/cache /cache

13
src/interface/event.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "core/types.h"
namespace interface
{
struct Event
{
enum class Type {
START,
} type;
};
}

View File

@ -5,10 +5,13 @@
namespace interface namespace interface
{ {
struct Event;
struct Module struct Module
{ {
virtual ~Module(){}; virtual ~Module(){};
virtual void start() = 0; virtual void event(const interface::Event &event) = 0;
virtual int test_add(int a, int b) = 0; virtual int test_add(int a, int b) = 0;
}; };
} }

View File

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include "interface/module.h" #include "interface/module.h"
#include "interface/server.h" #include "interface/server.h"
#include "interface/event.h"
#include <iostream> #include <iostream>
extern server::Config g_server_config; extern server::Config g_server_config;
@ -34,7 +35,9 @@ struct CState: public State, public interface::Server
m_compiler->construct(module_name.c_str(), this)); m_compiler->construct(module_name.c_str(), this));
//int a = m->test_add(1, 2); //int a = m->test_add(1, 2);
//std::cout<<"a = "<<a<<std::endl; //std::cout<<"a = "<<a<<std::endl;
m->start(); interface::Event event;
event.type = interface::Event::Type::START;
m->event(event);
} }
void load_modules(const ss_ &path) void load_modules(const ss_ &path)

View File

@ -1,8 +1,11 @@
#include "interface/module.h" #include "interface/module.h"
#include "interface/server.h" #include "interface/server.h"
#include "interface/fs.h" #include "interface/fs.h"
#include "interface/event.h"
#include <iostream> #include <iostream>
using interface::Event;
struct Module: public interface::Module struct Module: public interface::Module
{ {
interface::Server *m_server; interface::Server *m_server;
@ -18,6 +21,20 @@ struct Module: public interface::Module
std::cout<<"__loader destruct"<<std::endl; std::cout<<"__loader destruct"<<std::endl;
} }
void event(const interface::Event &event)
{
switch(event.type){
case Event::Type::START:
start();
break;
}
}
int test_add(int a, int b)
{
return a + b;
}
void start() void start()
{ {
auto list = interface::getGlobalFilesystem()->list_directory(m_server->get_modules_path()); auto list = interface::getGlobalFilesystem()->list_directory(m_server->get_modules_path());
@ -27,11 +44,6 @@ struct Module: public interface::Module
m_server->load_module(n.name, m_server->get_modules_path()+"/"+n.name); m_server->load_module(n.name, m_server->get_modules_path()+"/"+n.name);
} }
} }
int test_add(int a, int b)
{
return a + b;
}
}; };
extern "C" { extern "C" {

View File

@ -1,7 +1,10 @@
#include "interface/module.h" #include "interface/module.h"
#include "interface/server.h" #include "interface/server.h"
#include "interface/event.h"
#include <iostream> #include <iostream>
using interface::Event;
struct Module: public interface::Module struct Module: public interface::Module
{ {
Module() Module()
@ -14,14 +17,23 @@ struct Module: public interface::Module
std::cout<<"test1 destruct"<<std::endl; std::cout<<"test1 destruct"<<std::endl;
} }
void start() void event(const interface::Event &event)
{ {
switch(event.type){
case Event::Type::START:
start();
break;
}
} }
int test_add(int a, int b) int test_add(int a, int b)
{ {
return a + b; return a + b;
} }
void start()
{
}
}; };
extern "C" { extern "C" {