help_vars.Add(BoolVariable('WITH_TCP', 'Build with TCP adapter', False))
help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
help_vars.Add(EnumVariable('WITH_RD', 'Build including Resource Directory', '0', allowed_values=('0', '1')))
-help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including Cloud client sample', False))
+help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including Cloud Connector and Cloud Client sample', False))
help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False))
if target_os in ['darwin', 'ios']:
examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+if env.get('WITH_CLOUD'):
+ examples_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
######################################################################
# Source files and Targets
######################################################################
/** To represent resource type with Publish RD.*/
#define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdpub"
+/** Cloud Account */
+
+/** Account URI.*/
+#define OC_RSRVD_ACCOUNT_URI "/.well-known/ocf/account"
+
+/** Account session URI.*/
+#define OC_RSRVD_ACCOUNT_SESSION_URI "/.well-known/ocf/account/session"
+
+/** Account token refresh URI.*/
+#define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/.well-known/ocf/account/tokenrefresh"
+
+/** Defines auth provider. */
+#define OC_RSRVD_AUTHPROVIDER "authprovider"
+
+/** Defines auth code. */
+#define OC_RSRVD_AUTHCODE "authcode"
+
+/** Defines session. */
+#define OC_RSRVD_ACCESS_TOKEN "accesstoken"
+
+/** Defines status. */
+#define OC_RSRVD_STATUS "status"
+
+/** Defines grant type. */
+#define OC_RSRVD_GRANT_TYPE "granttype"
+
+/** Defines refresh token. */
+#define OC_RSRVD_REFRESH_TOKEN "refreshtoken"
+
+/** To represent grant type with refresh token. */
+#define OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN "refresh_token"
+
/**
* Mark a parameter as unused. Used to prevent unused variable compiler warnings.
* Used in three cases:
if examples_env.get('LOGGING'):
examples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+if examples_env.get('WITH_CLOUD'):
+ examples_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
if target_os in ['msys_nt', 'windows']:
examples_env.AppendUnique(LIBS = ['Comctl32', 'Gdi32', 'User32'])
-if examples_env.get('LOGGING'):
- examples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-
def make_single_file_cpp_program(program_name):
return examples_env.Program(program_name, program_name + ".cpp")
const std::string& uri,
const OCRepresentation& rep, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions,
+ OCConnectivityType connectivityType,
PostCallback& callback, QualityOfService QoS) = 0;
virtual OCStackResult DeleteResource(
const OCDevAddr& devAddr,
const std::string& uri,
const OCRepresentation& attributes, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS);
+ const HeaderOptions& headerOptions, OCConnectivityType connectivityType,
+ PostCallback& callback, QualityOfService QoS);
virtual OCStackResult DeleteResource(
const OCDevAddr& devAddr,
OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
const std::string& pinNumber,
DirectPairingCallback resultCallback);
+#ifdef WITH_CLOUD
+ /**
+ * API for Account Registration to Account Server
+ * @note Not supported on client mode for now since device id is not generated yet on
+ * client mode. So it should be server or both mode for API to work.
+ *
+ * @param host Host IP Address of a account server.
+ * @param authProvider Provider name used for authentication.
+ * @param authCode The authorization code obtained by using an authorization server
+ * as an intermediary between the client and resource owner.
+ * @param connectivityType ::OCConnectivityType type of connectivity indicating the
+ * interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
+ * @param cloudConnectHandler Callback function that will get the result of the operation.
+ *
+ * @return Returns ::OC_STACK_OK if success
+ */
+ OCStackResult signUp(const std::string& host,
+ const std::string& authProvider,
+ const std::string& authCode,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ /**
+ * API for Sign-In to Account Server
+ * @note Not supported on client mode for now since device id is not generated yet on
+ * client mode. So it should be server or both mode for API to work.
+ *
+ * @param host Host IP Address of a account server.
+ * @param accessToken Identifier of the resource obtained by account registration.
+ * @param connectivityType ::OCConnectivityType type of connectivity indicating the
+ * interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
+ * @param cloudConnectHandler Callback function that will get the result of the operation.
+ *
+ * @return Returns ::OC_STACK_OK if success
+ */
+ OCStackResult signIn(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ /**
+ * API for Sign-Out to Account Server
+ * @note Not supported on client mode for now since device id is not generated yet on
+ * client mode. So it should be server or both mode for API to work.
+ *
+ * @param host Host IP Address of a account server.
+ * @param accessToken Identifier of the resource obtained by account registration.
+ * @param connectivityType ::OCConnectivityType type of connectivity indicating the
+ * interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
+ * @param cloudConnectHandler Callback function that will get the result of the operation.
+ *
+ * @return Returns ::OC_STACK_OK if success
+ */
+ OCStackResult signOut(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ /**
+ * API for Refresh Access token to Account Server
+ * @note Not supported on client mode for now since device id is not generated yet on
+ * client mode. So it should be server or both mode for API to work.
+ *
+ * @param host Host IP Address of a account server.
+ * @param refreshToken Refresh token used for access token refresh.
+ * @param connectivityType ::OCConnectivityType type of connectivity indicating the
+ * interface. Example: CT_DEFAULT, CT_ADAPTER_IP, CT_ADAPTER_TCP.
+ * @param cloudConnectHandler Callback function that will get the result of the operation.
+ *
+ * @return Returns ::OC_STACK_OK if success
+ */
+ OCStackResult refreshAccessToken(const std::string& host,
+ const std::string& refreshToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+#endif // WITH_CLOUD
}
}
OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
const std::string& pinNumber,
DirectPairingCallback resultCallback);
-
+#ifdef WITH_CLOUD
+ OCStackResult signUp(const std::string& host,
+ const std::string& authProvider,
+ const std::string& authCode,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ OCStackResult signIn(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ OCStackResult signOut(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ OCStackResult signInOut(const std::string& host,
+ const std::string& accessToken,
+ bool isSignIn,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+
+ OCStackResult refreshAccessToken(const std::string& host,
+ const std::string& refreshToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler);
+#endif // WITH_CLOUD
private:
PlatformConfig m_cfg;
const OCRepresentation& /*attributes*/,
const QueryParamsMap& /*queryParams*/,
const HeaderOptions& /*headerOptions*/,
+ OCConnectivityType /*connectivityType*/,
PostCallback& /*callback*/, QualityOfService /*QoS*/)
{return OC_STACK_NOTIMPL;}
const std::string& uri,
const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
+ OCConnectivityType connectivityType,
PostCallback& callback, QualityOfService QoS)
{
if (!callback)
result = OCDoResource(nullptr, OC_REST_POST,
url.c_str(), &devAddr,
assembleSetResourcePayload(rep),
- CT_DEFAULT,
+ connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
assembleHeaderOptions(options, headerOptions),
return OCPlatform_impl::Instance().doDirectPairing(peer, pmSel,
pinNumber, resultCallback);
}
+#ifdef WITH_CLOUD
+ OCStackResult signUp(const std::string& host,
+ const std::string& authProvider,
+ const std::string& authCode,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return OCPlatform_impl::Instance().signUp(host, authProvider, authCode,
+ connectivityType, cloudConnectHandler);
+ }
+
+ OCStackResult signIn(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return OCPlatform_impl::Instance().signIn(host, accessToken,
+ connectivityType, cloudConnectHandler);
+ }
+ OCStackResult signOut(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return OCPlatform_impl::Instance().signOut(host, accessToken,
+ connectivityType, cloudConnectHandler);
+ }
+
+ OCStackResult refreshAccessToken(const std::string& host,
+ const std::string& refreshToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return OCPlatform_impl::Instance().refreshAccessToken(host, refreshToken,
+ connectivityType, cloudConnectHandler);
+ }
+#endif // WITH_CLOUD
} // namespace OCPlatform
} //namespace OC
return checked_guard(m_client, &IClientWrapper::DoDirectPairing,
peer, pmSel, pinNumber, resultCallback);
}
+#ifdef WITH_CLOUD
+ OCStackResult OCPlatform_impl::signUp(const std::string& host,
+ const std::string& authProvider,
+ const std::string& authCode,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ const char* di = OCGetServerInstanceIDString();
+ if (!di)
+ {
+ oclog() << "The mode should be Server or Both to generate UUID" << std::flush;
+ return result_guard(OC_STACK_ERROR);
+ }
+ std::string deviceId(di);
+
+ OCRepresentation rep;
+ rep.setValue(OC_RSRVD_DEVICE_ID, deviceId);
+ rep.setValue(OC_RSRVD_AUTHPROVIDER, authProvider);
+ rep.setValue(OC_RSRVD_AUTHCODE, authCode);
+
+ std::string uri = host + OC_RSRVD_ACCOUNT_URI;
+
+ OCDevAddr devAddr;
+ QueryParamsMap queryParams;
+ HeaderOptions headerOptions;
+ QualityOfService defaultQos = OC::QualityOfService::NaQos;
+ checked_guard(m_client, &IClientWrapper::GetDefaultQos, defaultQos);
+
+ return checked_guard(m_client, &IClientWrapper::PostResourceRepresentation,
+ devAddr, uri, rep, queryParams, headerOptions,
+ connectivityType, cloudConnectHandler, defaultQos);
+ }
+
+ OCStackResult OCPlatform_impl::signIn(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return signInOut(host, accessToken, true, connectivityType, cloudConnectHandler);
+ }
+
+ OCStackResult OCPlatform_impl::signOut(const std::string& host,
+ const std::string& accessToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ return signInOut(host, accessToken, false, connectivityType, cloudConnectHandler);
+ }
+
+ OCStackResult OCPlatform_impl::signInOut(const std::string& host,
+ const std::string& accessToken,
+ bool isSignIn,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ const char* di = OCGetServerInstanceIDString();
+ if (!di)
+ {
+ oclog() << "The mode should be Server or Both to generate UUID" << std::flush;
+ return result_guard(OC_STACK_ERROR);
+ }
+ std::string deviceId(di);
+
+ OCRepresentation rep;
+ rep.setValue(OC_RSRVD_DEVICE_ID, deviceId);
+ rep.setValue(OC_RSRVD_ACCESS_TOKEN, accessToken);
+ rep.setValue(OC_RSRVD_STATUS, isSignIn);
+
+ std::string uri = host + OC_RSRVD_ACCOUNT_SESSION_URI;
+
+ OCDevAddr devAddr;
+ QueryParamsMap queryParams;
+ HeaderOptions headerOptions;
+
+ QualityOfService defaultQos = OC::QualityOfService::NaQos;
+ checked_guard(m_client, &IClientWrapper::GetDefaultQos, defaultQos);
+
+ return checked_guard(m_client, &IClientWrapper::PostResourceRepresentation,
+ devAddr, uri, rep, queryParams, headerOptions,
+ connectivityType, cloudConnectHandler, defaultQos);
+ }
+
+ OCStackResult OCPlatform_impl::refreshAccessToken(const std::string& host,
+ const std::string& refreshToken,
+ OCConnectivityType connectivityType,
+ PostCallback cloudConnectHandler)
+ {
+ const char* di = OCGetServerInstanceIDString();
+ if (!di)
+ {
+ oclog() << "The mode should be Server or Both to generate UUID" << std::flush;
+ return result_guard(OC_STACK_ERROR);
+ }
+ std::string deviceId(di);
+
+ OCRepresentation rep;
+ rep.setValue(OC_RSRVD_DEVICE_ID, deviceId);
+ rep.setValue(OC_RSRVD_REFRESH_TOKEN, refreshToken);
+ rep.setValue(OC_RSRVD_GRANT_TYPE, OC_RSRVD_GRANT_TYPE_REFRESH_TOKEN);
+
+ std::string uri = host + OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI;
+
+ OCDevAddr devAddr;
+ QueryParamsMap queryParams;
+ HeaderOptions headerOptions;
+
+ QualityOfService defaultQos = OC::QualityOfService::NaQos;
+ checked_guard(m_client, &IClientWrapper::GetDefaultQos, defaultQos);
+
+ return checked_guard(m_client, &IClientWrapper::PostResourceRepresentation,
+ devAddr, uri, rep, queryParams, headerOptions,
+ connectivityType, cloudConnectHandler, defaultQos);
+ }
+#endif // WITH_CLOUD
} //namespace OC
{
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
m_devAddr, m_uri, rep, queryParametersMap,
- m_headerOptions, attributeHandler, QoS);
+ m_headerOptions, CT_DEFAULT, attributeHandler, QoS);
}
OCStackResult OCResource::post(const OCRepresentation& rep,
if secured == '1':
oclib_env.AppendUnique(LIBS=['tinydtls'])
+if oclib_env.get('WITH_CLOUD'):
+ oclib_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
######################################################################
# Source files and Targets
######################################################################
void pairedHandler(const PairedDevices& /*list*/)
{
}
-
+#ifdef WITH_CLOUD
+ void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
+ const int /*eCode*/)
+ {
+ }
+#endif
//Helper methods
void DeleteStringLL(OCStringLL* ll)
{
std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));
}
+#ifdef WITH_CLOUD
+ //SignUp Test
+ TEST(SignUpTest, DISABLED_SignUpWithValidParameters)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string authProvider("AnyAuthProvider");
+ std::string authCode("AnyAuthCode");
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::signUp(host, authProvider, authCode,
+ CT_DEFAULT, &accountHandler));
+ }
+
+ TEST(SignUpTest, SignUpWithNullCallback)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string authProvider("AnyAuthProvider");
+ std::string authCode("AnyAuthCode");
+ EXPECT_ANY_THROW(OCPlatform::signUp(host, authProvider, authCode, CT_DEFAULT, nullptr));
+ }
+
+ //SignIn Test
+ TEST(SignInTest, DISABLED_SignInWithValidParameters)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string accessToken("AnyAccessToken");
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::signIn(host, accessToken, CT_DEFAULT, &accountHandler));
+ }
+
+ TEST(SignInTest, SignInWithNullCallback)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string accessToken("AnyAccessToken");
+ EXPECT_ANY_THROW(OCPlatform::signIn(host, accessToken, CT_DEFAULT, nullptr));
+ }
+
+ //SignOut Test
+ TEST(SignOutTest, DISABLED_SignOutWithValidParameters)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string accessToken("AnyAccessToken");
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::signOut(host, accessToken,
+ CT_DEFAULT, &accountHandler));
+ }
+
+ TEST(SignOutTest, SignOutWithNullCallback)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string accessToken("AnyAccessToken");
+ EXPECT_ANY_THROW(OCPlatform::signOut(host, accessToken, CT_DEFAULT, nullptr));
+ }
+
+ //RefreshAccessToken Test
+ TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenWithValidParameters)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string refreshToken("AnyRefreshToken");
+ EXPECT_EQ(OC_STACK_OK, OCPlatform::refreshAccessToken(host, refreshToken,
+ CT_DEFAULT, &accountHandler));
+ }
+
+ TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
+ {
+ std::string host("coap+tcp://192.168.1.2:5000");
+ std::string refreshToken("AnyRefreshToken");
+ EXPECT_ANY_THROW(OCPlatform::refreshAccessToken(host, refreshToken, CT_DEFAULT, nullptr));
+ }
+#endif // WITH_CLOUD
}
if unittests_env.get('LOGGING'):
unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+if unittests_env.get('WITH_CLOUD'):
+ unittests_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD'])
+
######################################################################
# Source files and Targets
######################################################################