Skip to content

Commit

Permalink
addming map look up
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Teichtahl <marc@teichtahl.com>
  • Loading branch information
mteichtahl committed Jul 24, 2017
1 parent 6956cdc commit a27d95e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
57 changes: 30 additions & 27 deletions src/app/simhub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ std::shared_ptr<Attribute> FromCGeneric(genericTLV *generic)
{
std::shared_ptr<Attribute> retVal(new Attribute());

switch(generic->type) {
case CONFIG_BOOL:
retVal->setValue<bool>(generic->value.bool_value);
retVal->_type = BOOL_ATTRIBUTE;
break;
case CONFIG_FLOAT:
retVal->setValue<float>(generic->value.float_value);
retVal->_type = FLOAT_ATTRIBUTE;
break;
case CONFIG_INT:
retVal->setValue<int>(generic->value.int_value);
retVal->_type = INT_ATTRIBUTE;
break;
case CONFIG_STRING:
retVal->setValue<std::string>(generic->value.string_value);
retVal->_type = STRING_ATTRIBUTE;
break;
default:
assert(false);
break;
}
switch (generic->type) {
case CONFIG_BOOL:
retVal->setValue<bool>(generic->value.bool_value);
retVal->_type = BOOL_ATTRIBUTE;
break;
case CONFIG_FLOAT:
retVal->setValue<float>(generic->value.float_value);
retVal->_type = FLOAT_ATTRIBUTE;
break;
case CONFIG_INT:
retVal->setValue<int>(generic->value.int_value);
retVal->_type = INT_ATTRIBUTE;
break;
case CONFIG_STRING:
retVal->setValue<std::string>(generic->value.string_value);
retVal->_type = STRING_ATTRIBUTE;
break;
default:
assert(false);
break;
}

retVal->_name = generic->name;

Expand All @@ -46,7 +46,7 @@ SimHubEventController *SimHubEventController::EventControllerInstance(void)
return SimHubEventController::_EventControllerInstance;
}

SimHubEventController::SimHubEventController(void)
SimHubEventController::SimHubEventController()
{
_EventControllerInstance = this;
_prepare3dMethods.plugin_instance = NULL;
Expand All @@ -68,7 +68,9 @@ void SimHubEventController::prepare3dEventCallback(SPHANDLE eventSource, void *e
{
genericTLV *data = static_cast<genericTLV *>(eventData);
assert(data != NULL);
//std::cout << "prepare3d event " << data->name << ": " << attribute->getValueToString() << std::endl;
// std::cout << "prepare3d event " << data->name << std::endl;

// findMapping(data->name);
std::shared_ptr<Attribute> attribute = FromCGeneric(data);
_eventQueue.push(attribute);
}
Expand All @@ -78,7 +80,7 @@ void SimHubEventController::pokeyEventCallback(SPHANDLE eventSource, void *event
genericTLV *data = static_cast<genericTLV *>(eventData);
assert(data != NULL);
std::shared_ptr<Attribute> attribute = FromCGeneric(data);
//std::cout << "pokey event " << attribute->_name << ": " << attribute->getValueToString() << std::endl;
// std::cout << "pokey event " << attribute->_name << ": " << attribute->getValueToString() << std::endl;
_eventQueue.push(attribute);
}

Expand Down Expand Up @@ -109,7 +111,7 @@ simplug_vtable SimHubEventController::loadPlugin(std::string dylibName, EnqueueE

if (err == 0) {
err = pluginMethods.simplug_init(&pluginInstance, SimHubEventController::LoggerWrapper);

pluginMethods.plugin_instance = pluginInstance;

if (pluginMethods.simplug_preflight_complete(pluginInstance) == 0) {
Expand Down Expand Up @@ -163,8 +165,9 @@ void SimHubEventController::shutdownPlugin(simplug_vtable &pluginMethods)
// will awake and pop the event
void SimHubEventController::runEventLoop(void)
{
// clearly TODO
for (int i = 0; i < 100; i++) { // -- 9782 was crashing before we freed the uv buffer
// clearly TODO
// for (int i = 0; i < 100; i++) { // -- 9782 was crashing before we freed the uv buffer
while (true) {
std::shared_ptr<Attribute> data = _eventQueue.pop();
std::cout << "popped (" << data->_name << ": " << data->getValueToString() << ") off the concurrent event queue" << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/simhub.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __SIMHUB_H
#define __SIMHUB_H
#ifndef __SIMHUBEVENT_H
#define __SIMHUBEVENT_H

#include <string>
#include <thread>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int MappingConfigManager::init(void)
continue;
}

std::pair<std::map<std::string, std::pair<std::string, std::string>>::iterator, bool> ret;
std::pair<std::map<std::string, mapEntry>::iterator, bool> ret;
auto pair = std::make_pair(source, target);
ret = _mapping.insert(std::make_pair(source, pair));

Expand Down Expand Up @@ -118,3 +118,16 @@ std::string MappingConfigManager::version(void)

return _mappingConfigFileVersion;
}

bool MappingConfigManager::findMapping(std::string source, mapEntry *retMapEntry)
{
auto ret = _mapping.find(source);
if (ret != _mapping.end()) {
printf("%s", (char *)(&ret->second.second));
retMapEntry = &ret->second;
return true;
}
else {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#define RETURN_OK 1
#define RETURN_ERROR 0

typedef std::pair<std::string, std::string> mapEntry;
typedef std::map<std::string, mapEntry> ElementMap;

class MappingConfigManager
{
protected:
Expand All @@ -28,7 +31,7 @@ class MappingConfigManager
std::string _mappingConfigFileVersion;
std::string _configName;
libconfig::Setting *_root;
std::map<std::string, std::pair<std::string, std::string>> _mapping;
ElementMap _mapping;

public:
MappingConfigManager(std::string);
Expand All @@ -38,6 +41,7 @@ class MappingConfigManager
bool fileExists(std::string filename);
std::string getConfigFilename(void);
std::string version(void);
bool findMapping(std::string, mapEntry *);
};

#endif

0 comments on commit a27d95e

Please sign in to comment.