summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Factory.cpp
blob: ee2a3bd8ac1478feae627e6696602f65e3ef2dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "uscxml/Factory.h"
#include "uscxml/datamodel/ecmascript/v8/V8DataModel.h"
//#include "uscxml/ioprocessor/basichttp/pion/PionIOProcessor.h"
#include "uscxml/ioprocessor/basichttp/libevent/EventIOProcessor.h"
#include "uscxml/invoker/scxml/USCXMLInvoker.h"

namespace uscxml {

  Factory::Factory() {
    _dataModels["ecmascript"] = new V8DataModel();
//    _ioProcessors["basichttp"] = new PionIOProcessor();
    _ioProcessors["basichttp"] = new EventIOProcessor();
    _ioProcessors["http://www.w3.org/TR/scxml/#SCXMLEventProcessor"] = new EventIOProcessor();
    _invoker["scxml"] = new USCXMLInvoker();
    _invoker["http://www.w3.org/TR/scxml/"] = _invoker["scxml"];
  }
  
  void Factory::registerIOProcessor(const std::string type, IOProcessor* ioProcessor) {
    getInstance()->_ioProcessors[type] = ioProcessor;
  }
  
  void Factory::registerDataModel(const std::string type, DataModel* dataModel) {
    getInstance()->_dataModels[type] = dataModel;
  }
  
  void Factory::registerExecutableContent(const std::string tag, ExecutableContent* executableContent) {
    getInstance()->_executableContent[tag] = executableContent;
  }
  
  void Factory::registerInvoker(const std::string type, Invoker* invoker) {
    getInstance()->_invoker[type] = invoker;
  }

  Invoker* Factory::getInvoker(const std::string type, Interpreter* interpreter) {
    if (Factory::getInstance()->_invoker.find(type) != getInstance()->_invoker.end()) {
      return (Invoker*)getInstance()->_invoker[type]->create(interpreter);
    }
    return NULL;
  }

  DataModel* Factory::getDataModel(const std::string type, Interpreter* interpreter) {
    if (Factory::getInstance()->_dataModels.find(type) != getInstance()->_dataModels.end()) {
      return getInstance()->_dataModels[type]->create(interpreter);
    }
    return NULL;
  }
  
  IOProcessor* Factory::getIOProcessor(const std::string type, Interpreter* interpreter) {
    if (getInstance()->_ioProcessors.find(type) != getInstance()->_ioProcessors.end()) {
      return getInstance()->_ioProcessors[type]->create(interpreter);
    }
    return NULL;
  }
  
  ExecutableContent* Factory::getExecutableContent(const std::string tag, Interpreter* interpreter) {
    if (getInstance()->_executableContent.find(tag) != getInstance()->_executableContent.end()) {
      return getInstance()->_executableContent[tag]->create(interpreter);
    }
    return NULL;
  }
  
  Factory* Factory::getInstance() {
    if (_instance == NULL) {
      _instance = new Factory();
    }
    return _instance;
  }

  Factory* Factory::_instance = NULL;

}