Back to index

nordugrid-arc-nox  1.1.0~rc6
GlobusErrorUtils.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "GlobusErrorUtils.h"
00006 
00007 namespace Arc {
00008 
00009   std::ostream& operator<<(std::ostream& o, const GlobusResult& res) {
00010     if (res)
00011       return (o << "<success>");
00012     globus_object_t *err = globus_error_get(res);
00013     for (globus_object_t *err_ = err; err_;
00014         err_ = globus_error_base_get_cause(err_)) {
00015       if (err_ != err)
00016        o << "/";
00017       char *tmp = globus_object_printable_to_string(err_);
00018       if (tmp) {
00019        o << tmp;
00020        free(tmp);
00021       }
00022       else
00023        o << "unknown error";
00024     }
00025     if (err)
00026       globus_object_free(err);
00027     return o;
00028   }
00029 
00030   std::string GlobusResult::str() const {
00031     if (r == GLOBUS_SUCCESS)
00032       return "<success>";
00033     globus_object_t *err = globus_error_get(r);
00034     std::string s;
00035     for (globus_object_t *err_ = err; err_;
00036         err_ = globus_error_base_get_cause(err_)) {
00037       if (err_ != err)
00038        s += "/";
00039       char *tmp = globus_object_printable_to_string(err_);
00040       if (tmp) {
00041        s += tmp;
00042        free(tmp);
00043       }
00044       else
00045        s += "unknown error";
00046     }
00047     if (err)
00048       globus_object_free(err);
00049     return s;
00050   }
00051 
00052   std::ostream& operator<<(std::ostream& o, globus_object_t *err) {
00053     if (err == GLOBUS_NULL)
00054       return (o << "<success>");
00055     for (globus_object_t *err_ = err; err_;
00056         err_ = globus_error_base_get_cause(err_)) {
00057       if (err_ != err)
00058        o << "/";
00059       char *tmp = globus_object_printable_to_string(err_);
00060       if (tmp) {
00061        o << tmp;
00062        free(tmp);
00063       }
00064       else
00065        o << "unknown error";
00066     }
00067     return o;
00068   }
00069 
00070   std::string globus_object_to_string(globus_object_t *err) {
00071     if (err == GLOBUS_NULL)
00072       return "<success>";
00073     std::string s;
00074     for (globus_object_t *err_ = err; err_;
00075         err_ = globus_error_base_get_cause(err_)) {
00076       if (err_ != err)
00077        s += "/";
00078       char *tmp = globus_object_printable_to_string(err_);
00079       if (tmp) {
00080        s += tmp;
00081        free(tmp);
00082       }
00083       else
00084        s += "unknown error";
00085     }
00086     return s;
00087   }
00088 
00089 } // namespace Arc