globus_xio_util.h

00001 /*
00002  * Copyright 1999-2006 University of Chicago
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef GLOBUS_XIO_UTIL_INCLUDE
00018 #define GLOBUS_XIO_UTIL_INCLUDE
00019 
00020 #include "globus_xio.h"
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 globus_bool_t
00027 globus_xio_get_env_pair(
00028     const char *                        env_name,
00029     int *                               min,
00030     int *                               max);
00031 
00032 globus_bool_t
00033 globus_xio_error_is_eof(
00034     globus_result_t                     res);
00035 
00036 globus_bool_t
00037 globus_xio_error_is_canceled(
00038     globus_result_t                     res);
00039 
00040 globus_bool_t
00041 globus_xio_driver_error_match(
00042     globus_xio_driver_t                 driver,
00043     globus_object_t *                   error,
00044     int                                 type);
00045 
00046 globus_bool_t
00047 globus_xio_driver_error_match_with_cb(
00048     globus_xio_driver_t                 driver,
00049     globus_object_t *                   error,
00050     globus_extension_error_match_cb_t   callback,
00051     void *                              type);
00052 
00053 globus_bool_t
00054 globus_xio_error_match(
00055     globus_result_t                     result,
00056     int                                 type);
00057     
00058 void
00059 globus_xio_contact_destroy(
00060     globus_xio_contact_t *              contact_info);
00061 
00062 globus_result_t
00063 globus_xio_contact_parse(
00064     globus_xio_contact_t *              contact_info,
00065     const char *                        contact_string);
00066 
00067 globus_result_t
00068 globus_xio_contact_info_to_string(
00069     const globus_xio_contact_t *        contact_info,
00070     char **                             contact_string);
00071 
00072 globus_result_t
00073 globus_xio_contact_info_to_url(
00074     const globus_xio_contact_t *        contact_info,
00075     char **                             contact_string);
00076 
00077 globus_result_t
00078 globus_xio_contact_info_to_encoded_string(
00079     const globus_xio_contact_t *        contact_info,
00080     const globus_xio_contact_t *        encode_chars,
00081     char **                             contact_string);
00082 
00083 globus_result_t
00084 globus_xio_contact_copy(
00085     globus_xio_contact_t *              dst,
00086     const globus_xio_contact_t *        src);
00087 
00088 /*
00089  * Utility macros
00090  */
00091 
00092 /* all macros in this file require each function to 'declare' their name with
00093  * this
00094  */
00095 #ifdef __GNUC__
00096 #define GlobusXIOName(func) static const char * _xio_name __attribute__((__unused__)) = #func
00097 #else
00098 #define GlobusXIOName(func) static const char * _xio_name = #func
00099 #endif
00100 
00101 #define GlobusXIOErrorCanceled()                                            \
00102     globus_error_put(GlobusXIOErrorObjCanceled())
00103 
00104 #define GlobusXIOErrorObjCanceled()                                         \
00105     globus_error_construct_error(                                           \
00106         GLOBUS_XIO_MODULE,                                                  \
00107         GLOBUS_NULL,                                                        \
00108         GLOBUS_XIO_ERROR_CANCELED,                                          \
00109         __FILE__,                                                           \
00110         _xio_name,                                                          \
00111         __LINE__,                                                           \
00112         _XIOSL("Operation was canceled"))                                          
00113 #define GlobusXIOErrorTimeout()                                             \
00114     globus_error_put(GlobusXIOErrorObjTimeout())                               
00115 
00116 #define GlobusXIOErrorObjTimeout()                                          \
00117     globus_error_construct_error(                                           \
00118         GLOBUS_XIO_MODULE,                                                  \
00119         GlobusXIOErrorObjTimeoutOnly(),                                     \
00120         GLOBUS_XIO_ERROR_CANCELED,                                          \
00121         __FILE__,                                                           \
00122         _xio_name,                                                          \
00123         __LINE__,                                                           \
00124         _XIOSL("Operation was canceled"))
00125 
00126 #define GlobusXIOErrorObjTimeoutOnly()                                      \
00127     globus_error_construct_error(                                           \
00128         GLOBUS_XIO_MODULE,                                                  \
00129         GLOBUS_NULL,                                                        \
00130         GLOBUS_XIO_ERROR_TIMEOUT,                                           \
00131         __FILE__,                                                           \
00132         _xio_name,                                                          \
00133         __LINE__,                                                           \
00134         _XIOSL("Operation timed out"))
00135 
00136 #define GlobusXIOErrorObjEOF()                                              \
00137         globus_error_construct_error(                                       \
00138             GLOBUS_XIO_MODULE,                                              \
00139             GLOBUS_NULL,                                                    \
00140             GLOBUS_XIO_ERROR_EOF,                                           \
00141             __FILE__,                                                       \
00142             _xio_name,                                                      \
00143             __LINE__,                                                       \
00144             _XIOSL("An end of file occurred"))                                
00145                                                                             
00146 #define GlobusXIOErrorEOF()                                                 \
00147     globus_error_put(                                                       \
00148         GlobusXIOErrorObjEOF())                                             \
00149                                                                             
00150 #define GlobusXIOErrorInvalidCommand(cmd_number)                            \
00151     globus_error_put(                                                       \
00152         globus_error_construct_error(                                       \
00153             GLOBUS_XIO_MODULE,                                              \
00154             GLOBUS_NULL,                                                    \
00155             GLOBUS_XIO_ERROR_COMMAND,                                       \
00156             __FILE__,                                                       \
00157             _xio_name,                                                      \
00158             __LINE__,                                                       \
00159             _XIOSL("An invalid command (%d) was issued"),                   \
00160             (cmd_number)))                             
00161                                                                             
00162 #define GlobusXIOErrorContactString(reason)                                 \
00163     globus_error_put(                                                       \
00164         globus_error_construct_error(                                       \
00165             GLOBUS_XIO_MODULE,                                              \
00166             GLOBUS_NULL,                                                    \
00167             GLOBUS_XIO_ERROR_CONTACT_STRING,                                \
00168             __FILE__,                                                       \
00169             _xio_name,                                                      \
00170             __LINE__,                                                       \
00171             _XIOSL("Contact string invalid. %s"),                           \
00172             (reason)))                                 
00173                                                                             
00174 #define GlobusXIOErrorObjParameter(param_name)                              \
00175     globus_error_construct_error(                                           \
00176         GLOBUS_XIO_MODULE,                                                  \
00177         GLOBUS_NULL,                                                        \
00178         GLOBUS_XIO_ERROR_PARAMETER,                                         \
00179         __FILE__,                                                           \
00180         _xio_name,                                                          \
00181         __LINE__,                                                           \
00182         _XIOSL("Bad parameter, %s"),                                        \
00183         (param_name))
00184 
00185 #define GlobusXIOErrorParameter(param_name)                                 \
00186     globus_error_put(                                                       \
00187         GlobusXIOErrorObjParameter(param_name))
00188                                                                             
00189 #define GlobusXIOErrorObjMemory(mem_name)                                   \
00190         globus_error_construct_error(                                       \
00191             GLOBUS_XIO_MODULE,                                              \
00192             GLOBUS_NULL,                                                    \
00193             GLOBUS_XIO_ERROR_MEMORY,                                        \
00194             __FILE__,                                                       \
00195             _xio_name,                                                      \
00196             __LINE__,                                                       \
00197             _XIOSL("Memory allocation failed on %s"),                       \
00198             (mem_name))                               
00199                                                                             
00200 #define GlobusXIOErrorMemory(mem_name_obj)                                  \
00201     globus_error_put(                                                       \
00202         GlobusXIOErrorObjMemory(mem_name_obj))
00203                                                                             
00204 #define GlobusXIOErrorObjSystemError(system_func, _errno)                   \
00205         globus_error_wrap_errno_error(                                      \
00206             GLOBUS_XIO_MODULE,                                              \
00207             (_errno),                                                       \
00208             GLOBUS_XIO_ERROR_SYSTEM_ERROR,                                  \
00209             __FILE__,                                                       \
00210             _xio_name,                                                      \
00211             __LINE__,                                                       \
00212             _XIOSL("System error in %s"),                                   \
00213             (system_func))                           
00214 
00215 #define GlobusXIOErrorSystemError(system_func, _errno)                      \
00216     globus_error_put(                                                       \
00217         GlobusXIOErrorObjSystemError(system_func, _errno))
00218 
00219 #define GlobusXIOErrorSystemResource(reason)                                \
00220     globus_error_put(                                                       \
00221         globus_error_construct_error(                                       \
00222             GLOBUS_XIO_MODULE,                                              \
00223             GLOBUS_NULL,                                                    \
00224             GLOBUS_XIO_ERROR_SYSTEM_RESOURCE,                               \
00225             __FILE__,                                                       \
00226             _xio_name,                                                      \
00227             __LINE__,                                                       \
00228             _XIOSL("System resource error, %s"),                            \
00229             (reason)))                                 
00230                                                                             
00231 #define GlobusXIOErrorInvalidStack(reason)                                  \
00232     globus_error_put(                                                       \
00233         globus_error_construct_error(                                       \
00234             GLOBUS_XIO_MODULE,                                              \
00235             GLOBUS_NULL,                                                    \
00236             GLOBUS_XIO_ERROR_STACK,                                         \
00237             __FILE__,                                                       \
00238             _xio_name,                                                      \
00239             __LINE__,                                                       \
00240             _XIOSL("Invalid stack, %s"),                                    \
00241             (reason)))                                 
00242                                                                             
00243 #define GlobusXIOErrorInvalidDriver(reason)                                 \
00244     globus_error_put(                                                       \
00245         globus_error_construct_error(                                       \
00246             GLOBUS_XIO_MODULE,                                              \
00247             GLOBUS_NULL,                                                    \
00248             GLOBUS_XIO_ERROR_DRIVER,                                        \
00249             __FILE__,                                                       \
00250             _xio_name,                                                      \
00251             __LINE__,                                                       \
00252             _XIOSL("Invalid Driver, %s"),                                   \
00253             (reason)))                                 
00254                                                                             
00255 #define GlobusXIOErrorPass()                                                \
00256     globus_error_put(                                                       \
00257         globus_error_construct_error(                                       \
00258             GLOBUS_XIO_MODULE,                                              \
00259             GLOBUS_NULL,                                                    \
00260             GLOBUS_XIO_ERROR_PASS,                                          \
00261             __FILE__,                                                       \
00262             _xio_name,                                                      \
00263             __LINE__,                                                       \
00264             _XIOSL("Operation passed too far")))                                   
00265                                                                             
00266 #define GlobusXIOErrorAlreadyRegistered()                                   \
00267     globus_error_put(                                                       \
00268         globus_error_construct_error(                                       \
00269             GLOBUS_XIO_MODULE,                                              \
00270             GLOBUS_NULL,                                                    \
00271             GLOBUS_XIO_ERROR_ALREADY_REGISTERED,                            \
00272             __FILE__,                                                       \
00273             _xio_name,                                                      \
00274             __LINE__,                                                       \
00275             _XIOSL("Operation already registered")))                                    
00276                                                                             
00277 #define GlobusXIOErrorInvalidState(state)                                   \
00278     globus_error_put(                                                       \
00279         globus_error_construct_error(                                       \
00280             GLOBUS_XIO_MODULE,                                              \
00281             GLOBUS_NULL,                                                    \
00282             GLOBUS_XIO_ERROR_STATE,                                         \
00283             __FILE__,                                                       \
00284             _xio_name,                                                      \
00285             __LINE__,                                                       \
00286             _XIOSL("Unexpected state, %d"),                                 \
00287             (state)))                                  
00288                                                                             
00289 #define GlobusXIOErrorWrapFailed(failed_func, result)                       \
00290     globus_error_put(                                                       \
00291         globus_error_construct_error(                                       \
00292             GLOBUS_XIO_MODULE,                                              \
00293             globus_error_get((result)),                                     \
00294             GLOBUS_XIO_ERROR_WRAPPED,                                       \
00295             __FILE__,                                                       \
00296             _xio_name,                                                      \
00297             __LINE__,                                                       \
00298             _XIOSL("%s failed."),                                           \
00299             (failed_func)))
00300 
00301 #define GlobusXIOErrorWrapFailedWithMessage(result, format, arg)            \
00302     globus_error_put(                                                       \
00303         globus_error_construct_error(                                       \
00304             GLOBUS_XIO_MODULE,                                              \
00305             globus_error_get((result)),                                     \
00306             GLOBUS_XIO_ERROR_WRAPPED,                                       \
00307             __FILE__,                                                       \
00308             _xio_name,                                                      \
00309             __LINE__,                                                       \
00310             (format),                                                       \
00311             (arg)))
00312 
00313 #define GlobusXIOErrorWrapFailedWithMessage2(result, format, arg1, arg2)    \
00314     globus_error_put(                                                       \
00315         globus_error_construct_error(                                       \
00316             GLOBUS_XIO_MODULE,                                              \
00317             globus_error_get((result)),                                     \
00318             GLOBUS_XIO_ERROR_WRAPPED,                                       \
00319             __FILE__,                                                       \
00320             _xio_name,                                                      \
00321             __LINE__,                                                       \
00322             (format),                                                       \
00323             (arg1), (arg2)))
00324 
00325 #define GlobusXIOErrorNotRegistered()                                       \
00326     globus_error_put(                                                       \
00327         globus_error_construct_error(                                       \
00328             GLOBUS_XIO_MODULE,                                              \
00329             NULL,                                                           \
00330             GLOBUS_XIO_ERROR_NOT_REGISTERED,                                \
00331             __FILE__,                                                       \
00332             _xio_name,                                                      \
00333             __LINE__,                                                       \
00334             _XIOSL("Not registered.")))                            
00335 
00336 #define GlobusXIOErrorNotActivated()                                        \
00337     globus_error_put(                                                       \
00338         globus_error_construct_error(                                       \
00339             GLOBUS_XIO_MODULE,                                              \
00340             NULL,                                                           \
00341             GLOBUS_XIO_ERROR_NOT_ACTIVATED,                                 \
00342             __FILE__,                                                       \
00343             _xio_name,                                                      \
00344             __LINE__,                                                       \
00345             _XIOSL("Module not activated.")))
00346                                                                             
00347 #define GlobusXIOErrorUnloaded()                                            \
00348     globus_error_put(                                                       \
00349         globus_error_construct_error(                                       \
00350             GLOBUS_XIO_MODULE,                                              \
00351             NULL,                                                           \
00352             GLOBUS_XIO_ERROR_UNLOADED,                                      \
00353             __FILE__,                                                       \
00354             _xio_name,                                                      \
00355             __LINE__,                                                       \
00356             _XIOSL("Driver in handle has been unloaded.")))
00357 
00358 #define GlobusXIOErrorParse(arg)                                            \
00359     globus_error_put(                                                       \
00360         globus_error_construct_error(                                       \
00361             GLOBUS_XIO_MODULE,                                              \
00362             NULL,                                                           \
00363             GLOBUS_XIO_ERROR_PARSE,                                         \
00364             __FILE__,                                                       \
00365             _xio_name,                                                      \
00366             __LINE__,                                                       \
00367             _XIOSL("An error occured parsing the string: %s"), arg))
00368 
00369 
00370 #define GlobusIXIOUtilCopyNIovec(iov, iovc, siov, siovc, bytes)             \
00371     do                                                                      \
00372     {                                                                       \
00373         globus_size_t                   _i;                                 \
00374         globus_size_t                   _tb = 0;                            \
00375         globus_size_t                   _bytes;                             \
00376         const struct iovec *            _siov;                              \
00377         struct iovec *                  _iov;                               \
00378         int                             _iovc;                              \
00379         int                             _siovc;                             \
00380                                                                             \
00381         _siov = (siov);                                                     \
00382         _siovc = (siovc);                                                   \
00383         _iov = (iov);                                                       \
00384         _iovc = (iovc);                                                     \
00385         _bytes = (bytes);                                                   \
00386                                                                             \
00387         for(_i = 0; _i < _siovc && _tb < _bytes; _i++)                      \
00388         {                                                                   \
00389             if(_tb + _siov[_i].iov_len > _bytes)                            \
00390             {                                                               \
00391                 _iov[_i].iov_len = _bytes - _tb;                            \
00392             }                                                               \
00393             else                                                            \
00394             {                                                               \
00395                 _iov[_i].iov_len = _siov[_i].iov_len;                       \
00396             }                                                               \
00397             _tb += _siov[_i].iov_len;                                       \
00398             _iov[_i].iov_base = _siov[_i].iov_base;                         \
00399         }                                                                   \
00400         _iovc = _i;                                                         \
00401     } while(0)
00402 
00403 
00404                                                                             
00405 #define GlobusIXIOUtilTransferIovec(iov, siov, iovc)                        \
00406     do                                                                      \
00407     {                                                                       \
00408         int                             _i;                                 \
00409         const struct iovec *            _siov;                              \
00410         struct iovec *                  _iov;                               \
00411         int                             _iovc;                              \
00412                                                                             \
00413         _siov = (siov);                                                     \
00414         _iov = (iov);                                                       \
00415         _iovc = (iovc);                                                     \
00416                                                                             \
00417         for(_i = 0; _i < _iovc; _i++)                                       \
00418         {                                                                   \
00419             _iov[_i].iov_base = _siov[_i].iov_base;                         \
00420             _iov[_i].iov_len = _siov[_i].iov_len;                           \
00421         }                                                                   \
00422     } while(0)
00423 
00424 #define GlobusIXIOUtilAdjustIovec(iov, iovc, nbytes)                        \
00425     do                                                                      \
00426     {                                                                       \
00427         globus_size_t                   _n = (nbytes);                      \
00428                                                                             \
00429         if(_n > 0)                                                          \
00430         {                                                                   \
00431             struct iovec *              _iov = (iov);                       \
00432             int                         _iovc = (iovc);                     \
00433             int                         _i;                                 \
00434                                                                             \
00435             /* skip all completely filled iovecs */                         \
00436             for(_i = 0;                                                     \
00437                 _i < _iovc &&  _n >= _iov[_i].iov_len;                      \
00438                 _n -= _iov[_i].iov_len, _i++);                              \
00439                                                                             \
00440             if(_i < _iovc)                                                  \
00441             {                                                               \
00442                 _iov[_i].iov_base = (char *) _iov[_i].iov_base + _n;        \
00443                 _iov[_i].iov_len -= _n;                                     \
00444                 (iov) += _i;                                                \
00445             }                                                               \
00446                                                                             \
00447             (iovc) -= _i;                                                   \
00448         }                                                                   \
00449     } while(0)
00450 
00451 #define GlobusIXIOUtilTransferAdjustedIovec(                                \
00452     new_iov, new_iovc, iov, iovc, nbytes)                                   \
00453     do                                                                      \
00454     {                                                                       \
00455         globus_size_t                   _n;                                 \
00456         const struct iovec *            _iov;                               \
00457         int                             _iovc;                              \
00458         struct iovec *                  _new_iov;                           \
00459         int                             _i;                                 \
00460         int                             _j;                                 \
00461                                                                             \
00462         _iov = (iov);                                                       \
00463         _iovc = (iovc);                                                     \
00464         _new_iov = (new_iov);                                               \
00465                                                                             \
00466         /* skip all completely filled iovecs */                             \
00467         for(_i = 0, _n = (nbytes);                                          \
00468             _i < _iovc &&  _n >= _iov[_i].iov_len;                          \
00469             _n -= _iov[_i].iov_len, _i++);                                  \
00470                                                                             \
00471         (new_iovc) = _iovc - _i;                                            \
00472         if(_i < _iovc)                                                      \
00473         {                                                                   \
00474             _new_iov[0].iov_base = (char *) _iov[_i].iov_base + _n;         \
00475             _new_iov[0].iov_len = _iov[_i].iov_len - _n;                    \
00476                                                                             \
00477             /* copy remaining */                                            \
00478             for(_j = 1, _i++; _i < _iovc; _j++, _i++)                       \
00479             {                                                               \
00480                 _new_iov[_j].iov_base = _iov[_i].iov_base;                  \
00481                 _new_iov[_j].iov_len = _iov[_i].iov_len;                    \
00482             }                                                               \
00483         }                                                                   \
00484     } while(0)
00485 
00486 #define GlobusXIOUtilIovTotalLength(                                        \
00487     out_len, iov, iovc)                                                     \
00488     do                                                                      \
00489     {                                                                       \
00490         int                             _i;                                 \
00491         const struct iovec *            _iov;                               \
00492         int                             _iovc;                              \
00493         globus_size_t                   _out_len;                           \
00494         _iov = (iov);                                                       \
00495         _iovc = (iovc);                                                     \
00496         _out_len = 0;                                                       \
00497         for(_i = 0; _i < _iovc; _i++)                                       \
00498         {                                                                   \
00499             _out_len += _iov[_i].iov_len;                                   \
00500         }                                                                   \
00501         out_len = _out_len;                                                 \
00502     } while(0)
00503 
00504 #define GlobusXIOUtilIovSerialize(                                          \
00505     out_buf, iov, iovc)                                                     \
00506     do                                                                      \
00507     {                                                                       \
00508         int                             _i;                                 \
00509         int                             _ndx = 0;                           \
00510         for(_i = 0; _i < iovc; _i++)                                        \
00511         {                                                                   \
00512             memcpy(&(out_buf)[_ndx], (iov)[_i].iov_base, (iov)[_i].iov_len);\
00513             _ndx += (iov)[_i].iov_len;                                      \
00514         }                                                                   \
00515     } while(0)
00516 
00517 #ifdef __cplusplus
00518 }
00519 #endif
00520 
00521 #endif

Generated on 2 May 2016 for globus_xio by  doxygen 1.4.7