Extend ConnectorBase
To create a new connector, you must include the SDK header files in the source file. Add the following include statement at the top of the source file you created:
#include <autonomy/connector/connector.hpp>
So that the required classes are conveniently accessible, add the following using
statement within the namespace that defines your connector implementation:
namespace myconnectornamespace { using namespace autonomy::connector::cppsdk; ... } //namespace myconnectornamespace
Below the using
statement, define the main connector class. This class must extend the class ConnectorBase
from the cppsdk
namespace. It must also specify the display name of the connector, and which features are available:
class MyConnector : public ConnectorBase { public: MyConnector() : ConnectorBase("My Connector") {} Features::feature_type features() { return Features::synchronize; } void synchronize(const SynchronizeTask& task) { std::string target = task.taskConfig().get("Target", "World"); task.log().normal("Hello " + target); } };
This is not enough to build the connector; two additional functions must be defined that allow the library to create and destroy the connector instance. These functions are wrapped in a convenient macro that should be placed at the end of the file, outside the namespace:
CONNECTOR_LIBRARY_CLASS(myconnectornamespace::MyConnector)
NOTE: As shown in the example above, any connector implementation must extend ConnectorBase
.
The implementation of synchronize uses task.taskConfig()
and task.log()
which provide access to the configuration and log for the task.
The constructor of ConnectorBase
is passed the string "My Connector". This is the name of the connector as it is displayed to the user, and can be any string.
A Visual Studio project with this sample code is provided in the SDK (see the HelloWordConnector
project in the CodeSamples
solution).
This very basic connector implements only the synchronize
fetch action. Your class does not have to implement the synchronize
action, and it could implement other actions such as collect
, view
, update
, and delete
.
The body of the synchronize
method reads a configuration value and writes a log message. It reads the value of the Target
configuration parameter (which has a default value of "World") and then writes it to the synchronize log at the normal log level.