|
From: <mik...@us...> - 2008-09-22 23:53:18
|
Revision: 1030
http://omc.svn.sourceforge.net/omc/?rev=1030&view=rev
Author: mike-brasher
Date: 2008-09-22 23:53:09 +0000 (Mon, 22 Sep 2008)
Log Message:
-----------
Finished part I of CMPIStatus to CMPIException mapping (the C/SWIG
side).
Modified Paths:
--------------
cmpi-bindings/trunk/install.sh
cmpi-bindings/trunk/swig/cmpi.i
cmpi-bindings/trunk/swig/cmpi_callbacks.i
cmpi-bindings/trunk/swig/cmpi_types.i
cmpi-bindings/trunk/swig/python/cmpi_pywbem_bindings.py
cmpi-bindings/trunk/test/python/TestMethod.py
Modified: cmpi-bindings/trunk/install.sh
===================================================================
--- cmpi-bindings/trunk/install.sh 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/install.sh 2008-09-22 23:53:09 UTC (rev 1030)
@@ -43,5 +43,6 @@
fi
if [ "$1" = "sfcb" ]; then
+ echo "cp $SO /usr/lib64/"
cp $SO /usr/lib64/
fi
Modified: cmpi-bindings/trunk/swig/cmpi.i
===================================================================
--- cmpi-bindings/trunk/swig/cmpi.i 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/swig/cmpi.i 2008-09-22 23:53:09 UTC (rev 1030)
@@ -1,6 +1,7 @@
%module cmpi
%include "typemaps.i"
+%include exception.i
%{
#include <stdint.h>
@@ -16,7 +17,22 @@
#include <pthread.h>
-/* CMPIException */
+static CMPIData *
+clone_data(const CMPIData *dp)
+{
+ CMPIData *data = (CMPIData *)calloc(1, sizeof(CMPIData));
+ memcpy(data, dp, sizeof(CMPIData));
+ return data;
+}
+
+/*
+**==============================================================================
+**
+** struct _CMPIException
+**
+**==============================================================================
+*/
+
struct _CMPIException
{
int error_code;
@@ -25,50 +41,66 @@
typedef struct _CMPIException CMPIException;
-static CMPIData *
-clone_data(const CMPIData *dp)
+/*
+**==============================================================================
+**
+** raise_exception() and associated paraphernalia
+**
+**==============================================================================
+*/
+
+static pthread_once_t _once = PTHREAD_ONCE_INIT;
+static pthread_key_t _key;
+
+static void _init_key()
{
- CMPIData *data = (CMPIData *)calloc(1, sizeof(CMPIData));
- memcpy(data, dp, sizeof(CMPIData));
- return data;
+ pthread_key_create(&_key, NULL);
}
-/*
- * raise_exception()
- */
-
-pthread_once_t _once = PTHREAD_ONCE_INIT;
-
static void* _get_raised()
{
- return pthread_getspecific(_once);
+ pthread_once(&_once, _init_key);
+ return pthread_getspecific(_key);
}
static void _set_raised()
{
- static const char _data[] = "dummy string";
- pthread_setspecific(_once, (void*)_data);
+ pthread_once(&_once, _init_key);
+ pthread_setspecific(_key, (void*)1);
}
static void _clr_raised()
{
- pthread_setspecific(_once, NULL);
+ pthread_once(&_once, _init_key);
+ pthread_setspecific(_key, NULL);
}
void raise_exception(int error_code, const char* description)
{
- char buffer[1024];
- sprintf(buffer, "%d:%s", error_code, description);
+#ifdef SWIGPYTHON
+ PyObject* obj;
+ CMPIException* ex;
+
+ ex = (CMPIException*)malloc(sizeof(CMPIException));
+ ex->error_code = error_code;
+ ex->description = strdup(description);
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
- PyErr_SetString(PyExc_RuntimeError, buffer);
+ obj = SWIG_NewPointerObj(ex, SWIGTYPE_p__CMPIException, 1);
+ PyErr_SetObject(SWIG_Python_ExceptionType(SWIGTYPE_p__CMPIException), obj);
SWIG_PYTHON_THREAD_END_BLOCK;
_set_raised();
+#endif /* SWIGPYTHON */
}
/*
- * provider code
- */
+**==============================================================================
+**
+** raise_exception()
+** provider code
+**
+**==============================================================================
+*/
#if defined(SWIGRUBY)
#include "../src/cmpi_provider_ruby.c"
@@ -80,6 +112,9 @@
%}
+%exceptionclass CMPIException;
+%exceptionclass _CMPIException;
+
# Definitions
%include "cmpi_defs.i"
Modified: cmpi-bindings/trunk/swig/cmpi_callbacks.i
===================================================================
--- cmpi-bindings/trunk/swig/cmpi_callbacks.i 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/swig/cmpi_callbacks.i 2008-09-22 23:53:09 UTC (rev 1030)
@@ -7,17 +7,6 @@
%rename(CMPIBroker) CMPIBroker;
typedef struct _CMPIBroker {} CMPIBroker;
-%exception {
- _clr_raised();
- $action
- if (_get_raised())
- {
- _clr_raised();
- SWIG_PYTHON_THREAD_END_ALLOW;
- SWIG_fail;
- }
-}
-
%extend CMPIBroker {
void LogMessage(int severity, const char *id, const char *text) {
CMLogMessage($self, severity, id, text, NULL);
@@ -158,32 +147,3 @@
raise_exception(99, "oops");
}
}
-
-#-----------------------------------------------------
-#
-# CMPIException
-#
-
-%nodefault _CMPIException;
-%rename(CMPIException) CMPIException;
-typedef struct _CMPIException {} CMPIException;
-
-%extend CMPIException {
-
- CMPIException() {
- return (CMPIException*)calloc(1, sizeof(CMPIException));
- }
-
- ~CMPIException() {
- free($self->description);
- }
-
- int error_code() {
- return $self->error_code;
- }
-
- const char* get_description() {
- return $self->description;
- }
-}
-
Modified: cmpi-bindings/trunk/swig/cmpi_types.i
===================================================================
--- cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-22 23:53:09 UTC (rev 1030)
@@ -102,6 +102,54 @@
#-----------------------------------------------------
#
+# CMPIException
+#
+#-----------------------------------------------------
+
+%nodefault _CMPIException;
+%rename(CMPIException) CMPIException;
+typedef struct _CMPIException {} CMPIException;
+
+%extend CMPIException {
+
+ CMPIException() {
+ return (CMPIException*)calloc(1, sizeof(CMPIException));
+ }
+
+ ~CMPIException() {
+ free($self->description);
+ }
+
+ int get_error_code() {
+ return $self->error_code;
+ }
+
+ const char* get_description() {
+ return $self->description;
+ }
+}
+
+#-----------------------------------------------------
+#
+# %exception
+#
+#-----------------------------------------------------
+
+#ifdef SWIGPYTHON
+%exception {
+ _clr_raised();
+ $action
+ if (_get_raised())
+ {
+ _clr_raised();
+ SWIG_PYTHON_THREAD_END_ALLOW;
+ SWIG_fail;
+ }
+}
+#endif /* SWIGPYTHON */
+
+#-----------------------------------------------------
+#
# CMPIError
#
@@ -261,7 +309,6 @@
}
}
-
#-----------------------------------------------------
#
# CMPIObjectPath
Modified: cmpi-bindings/trunk/swig/python/cmpi_pywbem_bindings.py
===================================================================
--- cmpi-bindings/trunk/swig/python/cmpi_pywbem_bindings.py 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/swig/python/cmpi_pywbem_bindings.py 2008-09-22 23:53:09 UTC (rev 1030)
@@ -176,7 +176,10 @@
return bool(self.broker.classPathIsA(subObjPath,super))
def oops(self):
- self.broker.oops()
+ try:
+ self.broker.oops()
+ except cmpi.CMPIException,e:
+ print "exception: %d:%s" %(e.get_error_code(), e.get_description())
class Logger(object):
def __init__(self, broker):
Modified: cmpi-bindings/trunk/test/python/TestMethod.py
===================================================================
--- cmpi-bindings/trunk/test/python/TestMethod.py 2008-09-22 23:08:28 UTC (rev 1029)
+++ cmpi-bindings/trunk/test/python/TestMethod.py 2008-09-22 23:53:09 UTC (rev 1030)
@@ -63,14 +63,7 @@
'''
ch = env.get_cimom_handle()
- print "BEFORE"
-
- try:
- ch.oops()
- except RuntimeError:
- print "CAUGHT"
-
- print "AFTER"
+ ch.oops()
'''
for key in g_insts.keys():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|