@@ -19,10 +19,31 @@ using namespace Aws::Iotshadow;
19
19
using namespace Aws ::Iot::DeviceClient::Shadow;
20
20
using namespace Aws ::Iot::DeviceClient::Util;
21
21
using namespace Aws ::Iot::DeviceClient::Logging;
22
+ using namespace Aws ::Iot::DeviceClient;
22
23
23
24
constexpr char ConfigShadow::TAG[];
24
25
constexpr char ConfigShadow::DEFAULT_CONFIG_SHADOW_NAME[];
25
26
constexpr int ConfigShadow::DEFAULT_WAIT_TIME_SECONDS;
27
+
28
+ void ConfigShadow::updateLocalConfigFile (PlainConfig &config, const char * configFilePath)const
29
+ {
30
+ ofstream configFile (configFilePath);
31
+ JsonObject jsonObj;
32
+ // Convert config to JSON
33
+ config.SerializeToObject (jsonObj);
34
+
35
+ if (configFile.is_open ())
36
+ {
37
+ configFile << jsonObj.View ().WriteReadable ();
38
+ configFile.close ();
39
+ LOGM_INFO (TAG, " Updated configuration saved locally to disk at: %s" , configFilePath);
40
+ }
41
+ else
42
+ {
43
+ LOGM_WARN (TAG, " Failed to open config file: %s, Error: %s" , configFilePath, strerror (errno));
44
+ }
45
+ }
46
+
26
47
void ConfigShadow::getNamedShadowRejectedHandler (Iotshadow::ErrorResponse *errorResponse, int ioError)
27
48
{
28
49
if (ioError)
@@ -352,6 +373,17 @@ void ConfigShadow::resetClientConfigWithJSON(
352
373
PlainConfig::JSON_KEY_SAMPLE_SHADOW);
353
374
}
354
375
}
376
+
377
+ // Save the updated configuration to a local file for persistence
378
+ JsonObject jsonObj;
379
+ config.SerializeToObject (jsonObj);
380
+
381
+ const char * jsonStr = jsonObj.View ().WriteReadable ().c_str ();
382
+ LOGM_INFO (TAG, " Updating device configuration files with the following: %s" , jsonStr);
383
+
384
+ string userConfig = FileUtils::ExtractExpandedPath (Config::DEFAULT_CONFIG_FILE);
385
+ updateLocalConfigFile (config, userConfig.c_str ());
386
+ updateLocalConfigFile (config, Config::DEFAULT_ROOT_CONFIG_FILE);
355
387
}
356
388
357
389
void ConfigShadow::updateShadowWithLocalConfig (Iotshadow::IotShadowClient iotShadowClient, PlainConfig &config)
0 commit comments