Skip to content

Commit

Permalink
Merged testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Jul 30, 2019
2 parents 2a2a29f + c57f6f0 commit ffe331c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 94 deletions.
2 changes: 1 addition & 1 deletion revision.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38
40
10 changes: 5 additions & 5 deletions src/FlowException.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ namespace Flows
/**
* Base class for all Flow exceptions
*/
class FlowException
class FlowException : public std::exception
{
public:
FlowException(std::string message) { _message = message; }
virtual ~FlowException() {}
explicit FlowException(const std::string& message) { _message = message.c_str(); }
virtual ~FlowException() = default;

const std::string what() const { return _message; }
const char* what() const noexcept override { return _message; }
protected:
std::string _message;
const char* _message = nullptr;
};
}
#endif
55 changes: 30 additions & 25 deletions src/INode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,28 @@ INode::~INode()
_getConfigParameter = std::function<PVariable(std::string, std::string)>();
}

void INode::setLog(std::function<void(std::string, int32_t, std::string)> value)
void INode::setLog(std::function<void(const std::string&, int32_t,const std::string&)> value)
{
_log.swap(value);
if(_out) _out->setLog(&_log);
}

void INode::log(int32_t logLevel, std::string message)
void INode::log(int32_t logLevel, const std::string& message)
{
if(_log) _log(_id, logLevel, message);
}

void INode::subscribePeer(uint64_t peerId, int32_t channel, std::string variable)
void INode::frontendEventLog(const std::string& message)
{
if(_frontendEventLog) _frontendEventLog(_id, message);
}

void INode::subscribePeer(uint64_t peerId, int32_t channel, const std::string& variable)
{
if(_subscribePeer) _subscribePeer(_id, peerId, channel, variable);
}

void INode::unsubscribePeer(uint64_t peerId, int32_t channel, std::string variable)
void INode::unsubscribePeer(uint64_t peerId, int32_t channel, const std::string& variable)
{
if(_unsubscribePeer) _unsubscribePeer(_id, peerId, channel, variable);
}
Expand All @@ -106,22 +111,22 @@ void INode::unsubscribeGlobal()

void INode::output(uint32_t index, PVariable message, bool synchronous)
{
if(_output) _output(_id, index, message, synchronous);
if(_output) _output(_id, index, std::move(message), synchronous);
}

PVariable INode::invoke(std::string methodName, PArray parameters)
PVariable INode::invoke(const std::string& methodName, PArray parameters)
{
if(_invoke) return _invoke(methodName, parameters);
if(_invoke) return _invoke(methodName, std::move(parameters));
return Variable::createError(-32500, "No callback method set.");
}

PVariable INode::invokeNodeMethod(std::string nodeId, std::string methodName, PArray parameters, bool wait)
PVariable INode::invokeNodeMethod(const std::string& nodeId, const std::string& methodName, PArray parameters, bool wait)
{
if(_invokeNodeMethod) return _invokeNodeMethod(nodeId, methodName, parameters, wait);
if(_invokeNodeMethod) return _invokeNodeMethod(nodeId, methodName, std::move(parameters), wait);
return Variable::createError(-32500, "No callback method set.");
}

PVariable INode::invokeLocal(std::string methodName, PArray parameters)
PVariable INode::invokeLocal(const std::string& methodName, PArray parameters)
{
std::map<std::string, std::function<PVariable(PArray parameters)>>::iterator localMethodIterator = _localRpcMethods.find(methodName);
if(localMethodIterator == _localRpcMethods.end())
Expand All @@ -133,61 +138,61 @@ PVariable INode::invokeLocal(std::string methodName, PArray parameters)
return localMethodIterator->second(parameters);
}

void INode::nodeEvent(std::string topic, PVariable value)
void INode::nodeEvent(const std::string& topic, PVariable value)
{
if(_nodeEvent) _nodeEvent(_id, topic, value);
if(_nodeEvent) _nodeEvent(_id, topic, std::move(value));
}

PVariable INode::getNodeData(std::string key)
PVariable INode::getNodeData(const std::string& key)
{
if(_getNodeData) return _getNodeData(_id, key);
return Variable::createError(-32500, "No callback method set.");
}

void INode::setNodeData(std::string key, PVariable value)
void INode::setNodeData(const std::string& key, PVariable value)
{
if(_setNodeData) _setNodeData(_id, key, value);
if(_setNodeData) _setNodeData(_id, key, std::move(value));
}

PVariable INode::getFlowData(std::string key)
PVariable INode::getFlowData(const std::string& key)
{
if(_getFlowData) return _getFlowData(_flowId, key);
return Variable::createError(-32500, "No callback method set.");
}

void INode::setFlowData(std::string key, PVariable value)
void INode::setFlowData(const std::string& key, PVariable value)
{
if(_setFlowData) _setFlowData(_flowId, key, value);
if(_setFlowData) _setFlowData(_flowId, key, std::move(value));
}

PVariable INode::getGlobalData(std::string key)
PVariable INode::getGlobalData(const std::string& key)
{
if(_getGlobalData) return _getGlobalData(key);
return Variable::createError(-32500, "No callback method set.");
}

void INode::setGlobalData(std::string key, PVariable value)
void INode::setGlobalData(const std::string& key, PVariable value)
{
if(_setGlobalData) _setGlobalData(key, value);
if(_setGlobalData) _setGlobalData(key, std::move(value));
}

void INode::setInternalMessage(PVariable message)
{
if(_setInternalMessage) _setInternalMessage(_id, message);
if(_setInternalMessage) _setInternalMessage(_id, std::move(message));
}

PVariable INode::getConfigParameter(std::string nodeId, std::string name)
PVariable INode::getConfigParameter(const std::string& nodeId, const std::string& name)
{
if(_getConfigParameter) return _getConfigParameter(nodeId, name);
return Variable::createError(-32500, "No callback method set.");
}

PVariable INode::getNodeVariable(std::string variable)
PVariable INode::getNodeVariable(const std::string& variable)
{
return Flows::PVariable();
}

void INode::setNodeVariable(std::string variable, PVariable value)
void INode::setNodeVariable(const std::string& variable, PVariable value)
{
}

Expand Down
117 changes: 59 additions & 58 deletions src/INode.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ class INode
{
public:
INode(std::string path, std::string nodeNamespace, std::string type, const std::atomic_bool* frontendConnected);
INode(const INode&) = delete;
INode& operator=(const INode&) = delete;
virtual ~INode();

std::string getNamespace() { return _namespace; }
std::string getType() { return _type; }
std::string getPath() { return _path; }
std::string getFlowId() { return _flowId; }
void setFlowId(std::string value) { _flowId = value; }
void setFlowId(const std::string& value) { _flowId = value; }
std::string getId() { return _id; }
void setId(std::string value) { _id = value; if(_out) _out->setNodeId(value); }
std::mutex& getInputMutex() { return _inputMutex; }
Expand Down Expand Up @@ -101,38 +103,38 @@ class INode
/**
* Mustn't block.
*/
virtual PVariable getNodeVariable(std::string variable);
virtual PVariable getNodeVariable(const std::string& variable);

/**
* Mustn't block.
*/
virtual void setNodeVariable(std::string variable, PVariable value);
virtual void setNodeVariable(const std::string& variable, PVariable value);

/**
* Mustn't block.
*/
virtual PVariable getConfigParameterIncoming(std::string name) { return std::make_shared<Flows::Variable>(); }

// {{{ Internal methods
void setLog(std::function<void(std::string, int32_t, std::string)> value);
void setSubscribePeer(std::function<void(std::string, uint64_t, int32_t, std::string)> value) { _subscribePeer.swap(value); }
void setUnsubscribePeer(std::function<void(std::string, uint64_t, int32_t, std::string)> value) { _unsubscribePeer.swap(value); }
void setSubscribeFlow(std::function<void(std::string, std::string)> value) { _subscribeFlow.swap(value); }
void setUnsubscribeFlow(std::function<void(std::string, std::string)> value) { _unsubscribeFlow.swap(value); }
void setSubscribeGlobal(std::function<void(std::string)> value) { _subscribeGlobal.swap(value); }
void setUnsubscribeGlobal(std::function<void(std::string)> value) { _unsubscribeGlobal.swap(value); }
void setOutput(std::function<void(std::string, uint32_t, PVariable, bool)> value) { _output.swap(value); }
void setInvoke(std::function<PVariable(std::string, PArray)> value) { _invoke.swap(value); }
void setInvokeNodeMethod(std::function<PVariable(std::string, std::string, PArray, bool)> value) { _invokeNodeMethod.swap(value); }
void setNodeEvent(std::function<void(std::string, std::string, PVariable)> value) { _nodeEvent.swap(value); }
void setGetNodeData(std::function<PVariable(std::string, std::string)> value) { _getNodeData.swap(value); }
void setSetNodeData(std::function<void(std::string, std::string, PVariable)> value) { _setNodeData.swap(value); }
void setGetFlowData(std::function<PVariable(std::string, std::string)> value) { _getFlowData.swap(value); }
void setSetFlowData(std::function<void(std::string, std::string, PVariable)> value) { _setFlowData.swap(value); }
void setGetGlobalData(std::function<PVariable(std::string)> value) { _getGlobalData.swap(value); }
void setSetGlobalData(std::function<void(std::string, PVariable)> value) { _setGlobalData.swap(value); }
void setSetInternalMessage(std::function<void(std::string, PVariable)> value) { _setInternalMessage.swap(value); }
void setGetConfigParameter(std::function<PVariable(std::string, std::string)> value) { _getConfigParameter.swap(value); }
void setLog(std::function<void(const std::string&, int32_t, const std::string&)> value);
void setSubscribePeer(std::function<void(const std::string&, uint64_t, int32_t, const std::string&)> value) { _subscribePeer.swap(value); }
void setUnsubscribePeer(std::function<void(const std::string&, uint64_t, int32_t, const std::string&)> value) { _unsubscribePeer.swap(value); }
void setSubscribeFlow(std::function<void(const std::string&, const std::string&)> value) { _subscribeFlow.swap(value); }
void setUnsubscribeFlow(std::function<void(const std::string&, const std::string&)> value) { _unsubscribeFlow.swap(value); }
void setSubscribeGlobal(std::function<void(const std::string&)> value) { _subscribeGlobal.swap(value); }
void setUnsubscribeGlobal(std::function<void(const std::string&)> value) { _unsubscribeGlobal.swap(value); }
void setOutput(std::function<void(const std::string&, uint32_t, PVariable, bool)> value) { _output.swap(value); }
void setInvoke(std::function<PVariable(const std::string&, PArray)> value) { _invoke.swap(value); }
void setInvokeNodeMethod(std::function<PVariable(const std::string&, const std::string&, PArray, bool)> value) { _invokeNodeMethod.swap(value); }
void setNodeEvent(std::function<void(const std::string&, const std::string&, PVariable)> value) { _nodeEvent.swap(value); }
void setGetNodeData(std::function<PVariable(const std::string&, const std::string&)> value) { _getNodeData.swap(value); }
void setSetNodeData(std::function<void(const std::string&, const std::string&, PVariable)> value) { _setNodeData.swap(value); }
void setGetFlowData(std::function<PVariable(const std::string&, const std::string&)> value) { _getFlowData.swap(value); }
void setSetFlowData(std::function<void(const std::string&, const std::string&, PVariable)> value) { _setFlowData.swap(value); }
void setGetGlobalData(std::function<PVariable(const std::string&)> value) { _getGlobalData.swap(value); }
void setSetGlobalData(std::function<void(const std::string&, PVariable)> value) { _setGlobalData.swap(value); }
void setSetInternalMessage(std::function<void(const std::string&, PVariable)> value) { _setInternalMessage.swap(value); }
void setGetConfigParameter(std::function<PVariable(const std::string&, const std::string&)> value) { _getConfigParameter.swap(value); }
// }}}

/**
Expand All @@ -147,7 +149,7 @@ class INode
/**
* Executes local RPC method. Mustn't block.
*/
virtual PVariable invokeLocal(std::string methodName, PArray parameters);
virtual PVariable invokeLocal(const std::string& methodName, PArray parameters);
protected:
std::shared_ptr<Output> _out;
std::string _path;
Expand All @@ -162,51 +164,50 @@ class INode
*/
std::map<std::string, std::function<PVariable(PArray parameters)>> _localRpcMethods;

void log(int32_t logLevel, std::string message);
void subscribePeer(uint64_t peerId, int32_t channel = -1, std::string variable = "");
void unsubscribePeer(uint64_t peerId, int32_t channel = -1, std::string variable = "");
void log(int32_t logLevel, const std::string& message);
void frontendEventLog(const std::string& message);
void subscribePeer(uint64_t peerId, int32_t channel = -1, const std::string& variable = "");
void unsubscribePeer(uint64_t peerId, int32_t channel = -1, const std::string& variable = "");
void subscribeFlow();
void unsubscribeFlow();
void subscribeGlobal();
void unsubscribeGlobal();
void output(uint32_t outputIndex, PVariable message, bool synchronous = false);
PVariable invoke(std::string methodName, PArray parameters);
PVariable invokeNodeMethod(std::string nodeId, std::string methodName, PArray parameters, bool);
void nodeEvent(std::string topic, PVariable value);
PVariable getNodeData(std::string key);
void setNodeData(std::string key, PVariable value);
PVariable getFlowData(std::string key);
void setFlowData(std::string key, PVariable value);
PVariable getGlobalData(std::string key);
void setGlobalData(std::string key, PVariable value);
PVariable invoke(const std::string& methodName, PArray parameters);
PVariable invokeNodeMethod(const std::string& nodeId, const std::string& methodName, PArray parameters, bool);
void nodeEvent(const std::string& topic, PVariable value);
PVariable getNodeData(const std::string& key);
void setNodeData(const std::string& key, PVariable value);
PVariable getFlowData(const std::string& key);
void setFlowData(const std::string& key, PVariable value);
PVariable getGlobalData(const std::string& key);
void setGlobalData(const std::string& key, PVariable value);
void setInternalMessage(PVariable message);
PVariable getConfigParameter(std::string nodeId, std::string name);
PVariable getConfigParameter(const std::string& nodeId, const std::string& name);
private:
std::atomic_bool _locked;
std::atomic_int _referenceCounter;
std::mutex _inputMutex;
std::function<void(std::string, int32_t, std::string)> _log;
std::function<void(std::string, uint64_t, int32_t, std::string)> _subscribePeer;
std::function<void(std::string, uint64_t, int32_t, std::string)> _unsubscribePeer;
std::function<void(std::string, std::string)> _subscribeFlow;
std::function<void(std::string, std::string)> _unsubscribeFlow;
std::function<void(std::string)> _subscribeGlobal;
std::function<void(std::string)> _unsubscribeGlobal;
std::function<void(std::string, uint32_t, PVariable, bool)> _output;
std::function<PVariable(std::string, PArray)> _invoke;
std::function<PVariable(std::string, std::string, PArray, bool)> _invokeNodeMethod;
std::function<void(std::string, std::string, PVariable)> _nodeEvent;
std::function<PVariable(std::string, std::string)> _getNodeData;
std::function<void(std::string, std::string, PVariable)> _setNodeData;
std::function<PVariable(std::string, std::string)> _getFlowData;
std::function<void(std::string, std::string, PVariable)> _setFlowData;
std::function<PVariable(std::string)> _getGlobalData;
std::function<void(std::string, PVariable)> _setGlobalData;
std::function<void(std::string, PVariable)> _setInternalMessage;
std::function<PVariable(std::string, std::string)> _getConfigParameter;

INode(const INode&) = delete;
INode& operator=(const INode&) = delete;
std::function<void(const std::string&, int32_t, const std::string&)> _log;
std::function<void(const std::string&, const std::string&)> _frontendEventLog;
std::function<void(const std::string&, uint64_t, int32_t, const std::string&)> _subscribePeer;
std::function<void(const std::string&, uint64_t, int32_t, const std::string&)> _unsubscribePeer;
std::function<void(const std::string&, const std::string&)> _subscribeFlow;
std::function<void(const std::string&, const std::string&)> _unsubscribeFlow;
std::function<void(const std::string&)> _subscribeGlobal;
std::function<void(const std::string&)> _unsubscribeGlobal;
std::function<void(const std::string&, uint32_t, PVariable, bool)> _output;
std::function<PVariable(const std::string&, PArray)> _invoke;
std::function<PVariable(const std::string&, const std::string&, PArray, bool)> _invokeNodeMethod;
std::function<void(const std::string&, const std::string&, PVariable)> _nodeEvent;
std::function<PVariable(const std::string&, const std::string&)> _getNodeData;
std::function<void(const std::string&, const std::string&, PVariable)> _setNodeData;
std::function<PVariable(const std::string&, const std::string&)> _getFlowData;
std::function<void(const std::string&, const std::string&, PVariable)> _setFlowData;
std::function<PVariable(const std::string&)> _getGlobalData;
std::function<void(const std::string&, PVariable)> _setGlobalData;
std::function<void(const std::string&, PVariable)> _setInternalMessage;
std::function<PVariable(const std::string&, const std::string&)> _getConfigParameter;
};

typedef std::shared_ptr<INode> PINode;
Expand Down
2 changes: 1 addition & 1 deletion src/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace Flows
{

Output::Output(std::string& nodeId, std::function<void(std::string, int32_t, std::string)>* logMethod)
Output::Output(std::string& nodeId, std::function<void(const std::string&, int32_t, const std::string&)>* logMethod)
{
_nodeId = nodeId;
_log = logMethod;
Expand Down
6 changes: 3 additions & 3 deletions src/Output.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Output
/**
* The main constructor.
*/
Output(std::string& nodeId, std::function<void(std::string, int32_t, std::string)>* logMethod);
Output(std::string& nodeId, std::function<void(const std::string&, int32_t, const std::string&)>* logMethod);

/**
* The destructor.
Expand All @@ -68,7 +68,7 @@ class Output
*
* @param value The new log function.
*/
void setLog(std::function<void(std::string, int32_t, std::string)>* value) { _log = value; }
void setLog(std::function<void(const std::string&, int32_t, const std::string&)>* value) { _log = value; }

/**
* Prints an error message with filename, line number and function name.
Expand Down Expand Up @@ -160,7 +160,7 @@ class Output
*/
private:
std::string _nodeId;
std::function<void(std::string, int32_t, std::string)>* _log = nullptr;
std::function<void(const std::string&, int32_t, const std::string&)>* _log = nullptr;
};
}
#endif
2 changes: 1 addition & 1 deletion src/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool Variable::operator!=(const Variable& rhs)
return !(operator==(rhs));
}

Variable::operator Variable::bool_type() const
Variable::operator bool_type() const
{
bool result = false;
if(type != VariableType::tBoolean)
Expand Down

0 comments on commit ffe331c

Please sign in to comment.