To implement an API Function that has a Positional Argument list, follow the instructions in Declare the Functions and Create a Class for each API Function. Note the following differences from functions with named arguments with the following differences:
ApiFunctions.h
. If there are also functions with named arguments and ApiFunctionWithNamedArgs.h
is included, it is not necessary to include ApiFunctions.h
.This API function (int SendStringEcho(const char* stepName, const char* remoteHost, const char* value) might be declared in the header file, as follows:
class SendStringEcho : public CApiFunction { public: SendStringEcho( const char* mStepName, const char* mRemoteHost, const char* mValue); virtual ~SendStringEcho(); protected: virtual void Init(); virtual void Invoke(); virtual void Terminate(); virtual void Abort(); private: std::string m_stepName; std::string m_remoteHost; std::string m_value; };
The API function might be implemented with a class, as follows:
SendStringEcho::SendStringEcho( const char* mStepName, const char* mRemoteHost, const char* mValue) : CApiFunction( #ifdef WIN32 IDI_ECHO_STRING_EX, #else -1, #endif "Sending String ECHO") m_stepName(mStepName), m_remoteHost(mRemoteHost), m_value(mValue) { } SendStringEcho::~SendStringEcho() {} void SendStringEcho::Init() { foo(ALLOCATE, ALLRESOURCES); } void SendStringEcho::Invoke() { HandleRequest(m_remoteHost.c_str(), (void*)m_value.c_str(), m_value.size() ); } void SendStringEcho::Terminate() { // Release resources. foo(DEALLOCATE, ALLRESOURCES); } void SendStringEcho::Abort() { // Release resources. foo(DEALLOCATE, ALLRESOURCES); }