const std::string IoTivity::DEFAULT_PROVIDER = "samsung";
const int IoTivity::DEFAULT_TIMEOUT = 10;
-const char PERSISTENT_STORAGE_PATH[] = TOSTRING(PS_PATH) "/./nmlib_ps.dat"; /**< Path to persistent storage to get device id */
struct Params
{
IoTivity* IoTivity::instance = nullptr;
-static FILE* open_ps(const char*, const char *mode)
+static FILE* openPersistentStorage(const char*, const char *mode)
{
- return fopen(PERSISTENT_STORAGE_PATH, mode);
+ string path = IoTivity::getInstance()->getPersistentStoragePath();
+ return fopen(path.c_str(), mode);
}
std::string IoTivity::getAuthCode()
IoTivity::IoTivity(): signedIn(false)
{
- static OCPersistentStorage ps{open_ps, fread, fwrite, fclose, unlink};
+ persistentStoragePath = TOSTRING(PS_PATH) "/./nmlib_ps.dat";
+
+ static OCPersistentStorage ps{openPersistentStorage, fread, fwrite, fclose, unlink};
static OC::PlatformConfig pc{OC::ServiceType::InProc, OC::ModeType::Both,
"0.0.0.0", 0, OC::QualityOfService::HighQos, &ps};
params = new Params{pc};
{
if (instance == nullptr)
{
- cout << "PERSISTENT_STORAGE_PATH=" << PERSISTENT_STORAGE_PATH << endl;
try
{
instance = new IoTivity;
throw IoTInternalError("unsubscribeNotifications() not implemented", EC_NOT_IMPLEMENTED_YET);
}
+void IoTivity::setPersistentStoragePath(std::string newPath)
+{
+ persistentStoragePath = newPath;
+}
+
+std::string IoTivity::getPersistentStoragePath()
+{
+ return persistentStoragePath;
+}
+
}
* @brief getDeviceID returns device id (DUID) from iotivity persistant storage
* @return string that indicates duid
*/
- static std::string getDeviceID();
+ std::string getDeviceID();
/**
* @brief subscribeNotifications subscribes to secure server notifications.
*/
void unsubscribeNotifications();
+ /**
+ * @brief setPersistentStoragePath changes default path to persistent storage file (.dat)
+ * @param psPath path to persistent storage file (.dat)
+ */
+ void setPersistentStoragePath(std::string psPath);
+
+ /**
+ * @brief getPersistentStoragePath returns path to persistent storage file (.dat)
+ * @return path to persistent storage file (.dat)
+ */
+ std::string getPersistentStoragePath();
+
private:
static const std::string DEFAULT_PROVIDER;
static const int DEFAULT_TIMEOUT;
+ /**
+ * Path to persistent storage to get device id.
+ * Default depends on -DPS_PATH definition.
+ */
+ std::string persistentStoragePath;
+
IoTivity();
~IoTivity();
static IoTivity* instance;
string &json) :
Policy(name),
sender(sender_),
- device_id(NetworkManager::IoTivity::getDeviceID()),
+ device_id(NetworkManager::IoTivity::getInstance()->getDeviceID()),
action(action_)
{
params = params_;
string &json) :
Policy(name),
sender(sender_),
- device_id(NetworkManager::IoTivity::getDeviceID()),
+ device_id(NetworkManager::IoTivity::getInstance()->getDeviceID()),
action(action_)
{
params.push_back(params_);