/* teamtrack-module.h -- Python extension interfacing to TeamTrack Gareth Rees, Ravenbrook Limited, 2000-08-07 $Id: //info.ravenbrook.com/project/p4dti/version/0.2/code/python-teamtrack-interface/teamtrack-module.h#1 $ Common definitions for the project. */ #if !defined(TEAMTRACK_MODULE_H) #define TEAMTRACK_MODULE_H #include "Python.h" #include "TSServer.h" /* The declaration specifier EXPORTED indicates to Visual C++ that the function should be exported from the DLL. */ #ifdef WIN32 #define TEAMTRACK_EXPORTED __declspec(dllexport) #else #define TEAMTRACK_EXPORTED #endif /* teamtrack_error is a Python object (in Python it's called teamtrack.error) that represents errors generated by this interface module. */ extern PyObject *teamtrack_error; /* teamtrack_set_error(server) sets the current Python error to the most recent TeamTrack error for the given TeamShare server. */ extern void teamtrack_set_error(TSServer *server); /* teamtrack_raise(message, result). Raise a Python exception with teamtrack_error as the error object and the given message. Return result to indicate that an exception has been raised. */ #define teamtrack_raise(message, result) \ do { \ PyErr_SetString(teamtrack_error, (message)); \ return (result); \ } while (0) /* teamtrack_assert(expr, result). Evaluate expr and raise a Python exception if its value is zero. Return result to indicate that an exception has been raised. */ #define teamtrack_stringize(x) #x #define teamtrack_str(x) teamtrack_stringize(x) #define teamtrack_assert(expr, result) \ do { \ if (!(expr)) { \ teamtrack_raise("At line " teamtrack_str(__LINE__) " of " __FILE__ \ " the expression '" #expr "' was 0.", (result)); \ } \ } while (0) /* teamtrack_try(expr, server, result). Evaluate expr and raise a Python exception with an appropriate message if its value is not TS_OK. Return result to indicate that an exception has been raised. The error message is taken from the given TeamShare server. */ #define teamtrack_try(expr, server, result) \ do { \ int rc = (expr); \ if (rc != TS_OK) { \ teamtrack_set_error(server); \ return (result); \ } \ } while (0) /* teamtrack_check_type(classname, object, result). Check that object belongs to class (by calling class_p(object)). Raise a Python exception otherwise. Return reult to indicate that an exception has been raised. */ #define teamtrack_check_type(classname, object, result) \ do { \ if (!classname ## _p(object)) { \ PyErr_BadInternalCall(); \ return (result); \ } \ } while (0) #endif /* !defined(TEAMTRACK_MODULE_H) */