diff mbox series

[03/12] kernel-shark: Make KsSession::importFromFile return status flag

Message ID 20190314151012.905-4-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Headers show
Series Various modifications and fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov March 14, 2019, 3:10 p.m. UTC
The function has a better handling of the case when the session
description file cannot be loaded. It returns true on success,
otherwise false. We need this return flag in order to provide
adequate error message in the case when this operation fails.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsSession.cpp | 14 ++++++++++----
 kernel-shark/src/KsSession.hpp |  2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsSession.cpp b/kernel-shark/src/KsSession.cpp
index 2242a12..b151818 100644
--- a/kernel-shark/src/KsSession.cpp
+++ b/kernel-shark/src/KsSession.cpp
@@ -28,13 +28,19 @@  KsSession::~KsSession()
 }
 
 /** Import a user session from a Json file. */
-void KsSession::importFromFile(QString jfileName)
+bool KsSession::importFromFile(QString jfileName)
 {
-	if (_config)
+	kshark_config_doc *configTmp =
+		kshark_open_config_file(jfileName.toStdString().c_str(),
+					"kshark.config.session");
+
+	if (configTmp) {
 		kshark_free_config_doc(_config);
+		_config = configTmp;
+		return true;
+	}
 
-	_config = kshark_open_config_file(jfileName.toStdString().c_str(),
-					  "kshark.config.session");
+	return false;
 }
 
 /** Export the current user session from a Json file. */
diff --git a/kernel-shark/src/KsSession.hpp b/kernel-shark/src/KsSession.hpp
index f5ed5a1..b07c810 100644
--- a/kernel-shark/src/KsSession.hpp
+++ b/kernel-shark/src/KsSession.hpp
@@ -37,7 +37,7 @@  public:
 	/** Get the configuration document object. */
 	kshark_config_doc *getConfDocPtr() const {return _config;}
 
-	void importFromFile(QString jfileName);
+	bool importFromFile(QString jfileName);
 
 	void exportToFile(QString jfileName);