Use common code for retrieving a bool response.

Signed-off-by: Tony Asleson <tasle...@redhat.com>
---
 c_binding/lsm_mgmt.cpp | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 4aade5e..985a765 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -1546,6 +1546,25 @@ int lsm_access_groups_granted_to_volume(lsm_connect *c,
     return getAccessGroups(c, rc, response, groups, groupCount);
 }
 
+static int _retrieve_bool(int rc, Value &response, uint8_t *yes)
+{
+    int rc_out = rc;
+
+    *yes = 0;
+
+    if( LSM_ERR_OK == rc ) {
+        //We should be getting a boolean value back.
+        if( Value::boolean_t == response.valueType() ) {
+            if( response.asBool() ) {
+                *yes = 1;
+            }
+        } else {
+            rc_out = LSM_ERR_LIB_BUG;
+        }
+    }
+    return rc_out;
+}
+
 int lsm_volume_child_dependency(lsm_connect *c, lsm_volume *volume,
                                 uint8_t *yes, lsm_flag flags)
 {
@@ -1568,19 +1587,8 @@ int lsm_volume_child_dependency(lsm_connect *c, 
lsm_volume *volume,
         Value parameters(p);
         Value response;
 
-        *yes = 0;
-
         rc = rpc(c, "volume_child_dependency", parameters, response);
-        if( LSM_ERR_OK == rc ) {
-            //We should be getting a boolean value back.
-            if( Value::boolean_t == response.valueType() ) {
-                if( response.asBool() ) {
-                    *yes = 1;
-                }
-            } else {
-                rc = LSM_ERR_LIB_BUG;
-            }
-        }
+        rc = _retrieve_bool(rc, response, yes);
     } catch( const ValueException &ve ) {
         rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
                             ve.what());
@@ -1876,19 +1884,8 @@ int lsm_fs_child_dependency( lsm_connect *c, lsm_fs *fs, 
lsm_string_list *files,
         Value parameters(p);
         Value response;
 
-        *yes = 0;
-
         rc = rpc(c, "fs_child_dependency", parameters, response);
-        if( LSM_ERR_OK == rc ) {
-            //We should be getting a boolean value back.
-            if( Value::boolean_t == response.valueType() ) {
-                if( response.asBool() ) {
-                    *yes = 1;
-                }
-            } else {
-                rc = LSM_ERR_LIB_BUG;
-            }
-        }
+        rc = _retrieve_bool(rc, response, yes);
     } catch( const ValueException &ve ) {
         rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
                             ve.what());
-- 
1.8.2.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Libstoragemgmt-devel mailing list
Libstoragemgmt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libstoragemgmt-devel

Reply via email to