SDK  2.1.4
CloudBackend Software Development Kit - SDK API for C++
cbe::delegate::QueryDelegate Class Referenceabstract

#include <QueryDelegate.h>

Classes

struct  ErrorInfo
 
struct  Exception
 exception thrown by More...
 

Public Types

using Success = cbe::QueryResult
 
using Error = QueryError
 

Public Member Functions

virtual void onQuerySuccess (cbe::QueryResult &&queryResult)=0
 
virtual void onQueryError (cbe::delegate::QueryError &&error, cbe::util::Context &&context)=0
 

Detailed Description

Delegate class for the asynchronous version of methods:

Example
#include "cbe/delegate/QueryDelegate.h"
~~~
#include <condition_variable>
#include <mutex>
~~~
class MyQueryDelegate : public cbe::delegate::QueryDelegate {
std::mutex mutex{};
std::condition_variable conditionVariable{};
// Indicates operation completed - success or failure
bool called = false;
public:
ErrorInfo errorInfo{};
private:
// Called upon successful query.
void onQuerySuccess(cbe::QueryResult&& queryResult) final {
{
std::lock_guard<std::mutex> lock{mutex};
// Change state of queryResult member to indicate success
this->queryResult = std::move(queryResult);
// Indicate operation completed, member queryResult indicates success
called = true;
// If delegate is reused, clear possibly error state
errorInfo = ErrorInfo{};
}
conditionVariable.notify_one();
} // onQuerySuccess()
// Called upon a failed query() or join() call.
cbe::util::Context&& context) final {
{
std::lock_guard<std::mutex> lock{mutex};
// Activate errorInfo member to indicate no-success
errorInfo = ErrorInfo{std::move(context), std::move(error)};
// Indicate operation completed, member object indicates failure
called = true;
// If delegate is reused, clear possibly success state
queryResult = QueryResult{cbe::DefaultCtor{}};
}
conditionVariable.notify_one();
} // onQueryError()
public:
void waitForRsp() {
std::unique_lock<std::mutex> lock{mutex};
conditionVariable.wait(lock, [this] { return called; });
// Reset called flag, so current delegate instance can be reused
called = false;
} // waitForRsp()
}; // class MyQueryDelegate
resultset of data retrieved.
Definition: QueryResult.h:51
Definition: QueryDelegate.h:39
virtual void onQueryError(cbe::delegate::QueryError &&error, cbe::util::Context &&context)=0
virtual void onQuerySuccess(cbe::QueryResult &&queryResult)=0
Definition: QueryError.h:20
DefaultCtor
Default constructor marker.
Definition: Types.h:204
Definition: Context.h:11
Usage of the class above, see Example of asynchronous query

Member Function Documentation

◆ onQuerySuccess()

virtual void cbe::delegate::QueryDelegate::onQuerySuccess ( cbe::QueryResult &&  queryResult)
pure virtual

Called upon successful query.

Parameters
queryResultInstance of a QueryResult containing the result set.

◆ onQueryError()

virtual void cbe::delegate::QueryDelegate::onQueryError ( cbe::delegate::QueryError &&  error,
cbe::util::Context &&  context 
)
pure virtual

Called upon a failed query() or join() call.

Parameters
errorError information passed from CloudBackend SDK.
contextAdditional context information about the original service call that has failed.

The documentation for this class was generated from the following file: