Objects of this class lets C++ applications easily communicate with Unlimi-Tech's FileCatalyst Workflow/Spaces servers. More...
#include <FCWS.hpp>
Public Types | |
enum | EState { EState::kUnknown = 0, EState::kLoginDone, EState::kJobCreated, EState::kFileQueue, EState::kUploading, EState::kUploadDone, EState::kLogDone, EState::kFinalizeDone, EState::kFinished } |
Internal state of the WS object is only exposed for debugging or logging purposes. More... | |
Public Member Functions | |
WS () | |
Empty constructor. Nothing happens until login() is called. More... | |
~WS () | |
Destructor. More... | |
EState | get_state () const |
Get an enum that represents the internal state of the WS object. More... | |
WS & | login (const std::string &url, const std::string &name, const std::string &pass) |
Login to the Workflow/Spaces server using the given base URL, username, and password. More... | |
WS & | logout () |
The Workflow/Spaces server does not have the concept of logout, but calling this method will drop the session cookie and reset the internal state of the WS object (blanking out the username, password, URL, etc) effectively doing what would be expected when a user logs out. More... | |
WS & | createJob (const std::string &name, const StrMap &fields) |
Create the hot folder job. More... | |
WS & | queueSingleFile (const std::string &filename) |
Queue a single file to be uploaded. More... | |
WS & | queueRecursiveDirectory (const std::string &directory) |
Recursively traverse the specified directory and queue all files to be uploaded. More... | |
fc::GlobalStateAndStats | uploadQueuedFiles (fc::StatisticsCallback callback=nullptr, void *ptr=nullptr) |
Upload all the files that were previously queued with queueSingleFile() or queueRecursiveDirectory(). More... | |
WS & | doNothing () |
Prevent idle timeout or firewall timeout by sending a "do nothing" command to the server. More... | |
Static Public Member Functions | |
static void | initialize_third_party_libs () |
Initialize 3rd-party libs. More... | |
static StrMap | library_info () |
Returns a map of strings with information on both Workflow/Spaces and the support libraries that it is using internally. More... | |
Public Attributes | |
std::string | recent_url |
The full URL where WS most recently performed a GET or a POST request. More... | |
std::string | server_xml |
The XML the server sent back from the previous command. More... | |
std::string | server_reply |
Full output received from the server for the last command. More... | |
long | server_response_code |
HTTP response code (e.g., "200") received from the server for the last command. More... | |
bool | status_success |
The XML replies from the server contain a "status" node with an attribute named "success" . More... | |
std::string | message |
When a problem is detected, additional details may be stored in this string. More... | |
Objects of this class lets C++ applications easily communicate with Unlimi-Tech's FileCatalyst Workflow/Spaces servers.
Jobs can be created and individual or recursive directory uploads can be completed in just a few lines of C++.
For example:
Methods of interest:
When uploading files, an optional callback can be specified to uploadQueuedFiles() to receive transfer statistics once per second.
For example:
The callback is specified when the files are uploaded. For example:
|
strong |
Internal state of the WS
object is only exposed for debugging or logging purposes.
This state is not intended for users of the WS++ API, and may change or be removed in future versions.
Enumerator | |
---|---|
kUnknown | Invalid or unknown state. |
kLoginDone | Login was successful.
|
kJobCreated | Job creation was successful.
|
kFileQueue | Ready to queue files. |
kUploading | Upload in progress.
|
kUploadDone | Upload was successful.
|
kLogDone | Summary log was successful. |
kFinalizeDone | Finalize was successful. |
kFinished | Job has finished. |
fc::WS::WS | ( | ) |
Empty constructor. Nothing happens until login() is called.
fc::WS::~WS | ( | ) |
Destructor.
|
static |
Initialize 3rd-party libs.
This will initialize both libcurl and libxml2. If your application already uses and initializes these two libraries, then this call is not necessary. Otherwise, call this static function prior to instantiating the first WS
object.
For example:
Calling fs::WS::initialize_third_party_libs
() is equivalent to:
|
static |
Returns a map of strings with information on both Workflow/Spaces and the support libraries that it is using internally.
Mostly version strings for libraries. Useful for debug and logging purposes.
For example, the map returned could contain the following:
fc::WS::EState fc::WS::get_state | ( | ) | const |
Get an enum that represents the internal state of the WS
object.
For example:
The above code might display the state as "login done"
.
fc::WS & fc::WS::login | ( | const std::string & | url, |
const std::string & | name, | ||
const std::string & | pass | ||
) |
Login to the Workflow/Spaces server using the given base URL, username, and password.
All of the available forms and required fields should be listed in the resulting XML output.
For example:
fc::Exception | This method will throw a C++ exception if the login process fails. See FC++ Exceptions for details. |
fc::WS & fc::WS::logout | ( | ) |
The Workflow/Spaces server does not have the concept of logout, but calling this method will drop the session cookie and reset the internal state of the WS
object (blanking out the username, password, URL, etc) effectively doing what would be expected when a user logs out.
It is valid to call logout
() even when the WS
object is not logged in.
fc::WS & fc::WS::createJob | ( | const std::string & | name, |
const StrMap & | fields | ||
) |
Create the hot folder job.
The fields required are in the XML obtained after calling login().
For example:
fc::Exception | This method will throw a C++ exception if the create job process fails. See FC++ Exceptions for details. |
fc::WS & fc::WS::queueSingleFile | ( | const std::string & | filename | ) |
Queue a single file to be uploaded.
fc::Exception | This method will throw a C++ exception if the local file cannot be queued. See FC++ Exceptions for details. |
fc::WS & fc::WS::queueRecursiveDirectory | ( | const std::string & | directory | ) |
Recursively traverse the specified directory and queue all files to be uploaded.
fc::Exception | This method will throw a C++ exception if the local directory cannot be queued. See FC++ Exceptions for details. |
fc::GlobalStateAndStats fc::WS::uploadQueuedFiles | ( | fc::StatisticsCallback | callback = nullptr , |
void * | ptr = nullptr |
||
) |
Upload all the files that were previously queued with queueSingleFile() or queueRecursiveDirectory().
[in] | callback | A C-style function can be specified to receive a callback once per second when the transfer stats are updated during the upload. This callback interrupts the file transfer, so it must complete quickly. Additional details are available at fc::StatisticsCallback . |
[in] | ptr | A C-style "void *" user pointer that will also be passed to the callback. |
fc::GlobalStateAndStats
.For example:
This should produce output similar to this:
fc::Exception | This method will throw a C++ exception if the queued files cannot be uploaded. See FC++ Exceptions for details. |
fc::WS & fc::WS::doNothing | ( | ) |
Prevent idle timeout or firewall timeout by sending a "do nothing" command to the server.
It is the user's responsability to call this periodically from a secondary thread during long file transfers to prevent firewall timeouts of the Workflow/Spaces session.
fc::Exception | This method will throw a C++ exception if the "do nothing" request fails. See FC++ Exceptions for details. |
std::string fc::WS::recent_url |
The full URL where WS
most recently performed a GET or a POST request.
This is mostly for debug or logging purposes.
std::string fc::WS::server_xml |
The XML the server sent back from the previous command.
This is guaranteed to be either XML or an empty string. There are some commands – such as doNothing() – which return plain text versus XML, in which case this string will be blank.
std::string fc::WS::server_reply |
Full output received from the server for the last command.
This may be plain text or XML, depending on the previous command.
long fc::WS::server_response_code |
HTTP response code (e.g., "200") received from the server for the last command.
bool fc::WS::status_success |
The XML replies from the server contain a "status"
node with an attribute named "success"
.
For example:
The value in the "success"
attribute is stored in this boolean flag. Callers can then quickly determine if the previous command was successful.
For example:
status_success
flag since WS++ throws a C++ exception when an error is detected, such as when the "success"
attribute is set to "false"
. See FC++ Exceptions for details. std::string fc::WS::message |
When a problem is detected, additional details may be stored in this string.
If a C++ exception is thrown from within WS++, then the first line of the exception will also be stored in this text string for debug or logging purposes.