Forráskód Böngészése

1. Add cmake BUILD_PYTHON_MODULES option.
2. Rename log options getting functions.
3. py:
- pcilib_init_py() - extract pcilib_py_add_script_dir()
- pcilib_py_init_script() - extract view-specialized code to
pcilib_py_get_transform_script_properties()
3. pcilib_open():
- move pcilib_init_py() to previous position.
- add extract pcilib_py_add_script_dir()
4. pcilib_script_s - change hash key. Now it is (const char*) and contains
script file name with extension
5. pcipywrap:
- Add pcipywrap.h to remove swig generated file complile warnings
- remove -includeall swig flag to prevent crash in multi-thread scripts
- change set python expetion mechanic

Vasilii Chernov 8 éve
szülő
commit
3269dce328
12 módosított fájl, 180 hozzáadás és 156 törlés
  1. 12 4
      CMakeLists.txt
  2. 2 2
      pcilib/error.c
  3. 2 2
      pcilib/error.h
  4. 9 2
      pcilib/pci.c
  5. 80 44
      pcilib/py.c
  6. 8 3
      pcilib/py.h
  7. 1 2
      pcilib/xml.c
  8. 2 3
      pywrap/CMakeLists.txt
  9. 47 88
      pywrap/pcipywrap.c
  10. 4 0
      pywrap/pcipywrap.i
  11. 12 5
      views/transform.c
  12. 1 1
      views/transform.h

+ 12 - 4
CMakeLists.txt

@@ -7,7 +7,8 @@ cmake_minimum_required(VERSION 2.8)
 #set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH true)
 #set(CMAKE_PREFIX_PATH ${CMAKE_SYSTEM_PREFIX_PATH})
 
-set(DISABLE_PCITOOL FALSE CACHE BOOL "Build only the library") 
+set(DISABLE_PCITOOL FALSE CACHE BOOL "Build only the library")
+set(BUILD_PYTHON_MODULES FALSE CACHE BOOL "Build pcilib python modules") 
 
 #list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
 
@@ -35,8 +36,12 @@ SET(ENV{PKG_CONFIG_PATH} "${LIB_INSTALL_DIR}/pkgconfig:$ENV{PKG_CONFIG_PATH}")
 
 find_package(PkgConfig REQUIRED)
 find_package(Threads REQUIRED)
-find_package(PythonLibs 2.7 REQUIRED)
-find_package(SWIG REQUIRED)
+
+if (BUILD_PYTHON_MODULES)
+	find_package(PythonLibs 2.7 REQUIRED)
+	find_package(SWIG REQUIRED)
+	add_definitions(-DBUILD_PYTHON_MODULES)
+endif (BUILD_PYTHON_MODULES)
 
 set(EXTRA_SYSTEM_LIBS -lrt)
 
@@ -79,11 +84,14 @@ add_subdirectory(dma)
 add_subdirectory(protocols)
 add_subdirectory(views)
 add_subdirectory(pcilib)
-add_subdirectory(pywrap)
 add_subdirectory(pcitool)
 add_subdirectory(apps)
 add_subdirectory(xml)
 
+if (BUILD_PYTHON_MODULES)
+	add_subdirectory(pywrap)
+endif (BUILD_PYTHON_MODULES)
+
 set_target_properties(pcilib PROPERTIES
     VERSION ${PCILIB_VERSION}
     SOVERSION ${PCILIB_ABI_VERSION}

+ 2 - 2
pcilib/error.c

@@ -80,10 +80,10 @@ int pcilib_set_logger(pcilib_log_priority_t min_prio, pcilib_logger_t logger, vo
 pcilib_logger_t pcilib_get_logger() {
     return pcilib_logger;
 }
-pcilib_log_priority_t pcilib_get_logger_min_prio() {
+pcilib_log_priority_t pcilib_get_log_level() {
 	return pcilib_logger_min_prio;
 }
-void* pcilib_get_logger_argument() {
+void* pcilib_get_logger_context() {
 	return pcilib_logger_argument;
 }
 

+ 2 - 2
pcilib/error.h

@@ -48,12 +48,12 @@ pcilib_logger_t pcilib_get_logger();
 /**
  * Gets current logger min priority.
  */
-pcilib_log_priority_t pcilib_get_logger_min_prio();
+pcilib_log_priority_t pcilib_get_log_level();
 
 /**
  * Gets current logger argument.
  */
-void* pcilib_get_logger_argument();
+void* pcilib_get_logger_context();
 
 #ifdef __cplusplus
 }

+ 9 - 2
pcilib/pci.c

@@ -144,6 +144,13 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
 	    pcilib_close(ctx);
 	    return NULL;
 	}
+	
+	err = pcilib_init_py(ctx);
+	if (err) {
+	    pcilib_error("Error (%i) initializing python subsystem", err);
+	    pcilib_close(ctx);
+	    return NULL;
+	}
 
 	ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE;
 	ctx->alloc_views = PCILIB_DEFAULT_VIEW_SPACE;
@@ -185,9 +192,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
 	if (!ctx->model)
 	    ctx->model = strdup(model?model:"pci");
 	    
-	err = pcilib_init_py(ctx);
+	err = pcilib_py_add_script_dir(ctx);
 	if (err) {
-	    pcilib_error("Error (%i) initializing python subsystem", err);
+	    pcilib_error("Error (%i) add script path to python path", err);
 	    pcilib_close(ctx);
 	    return NULL;
 	}

+ 80 - 44
pcilib/py.c

@@ -1,4 +1,6 @@
+#ifdef BUILD_PYTHON_MODULES
 #include <Python.h>
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -11,11 +13,10 @@
 #include "py.h"
 #include "error.h"
 
+#ifdef BUILD_PYTHON_MODULES
 typedef struct pcilib_script_s {
-	char* name;
-    PyObject *module;	/**< PyModule object, contains script enviroment */
-	pcilib_access_mode_t mode;
-	
+	const char* name;
+    PyObject *module;	/**< PyModule object, contains script enviroment */	
 	UT_hash_handle hh;
 } pcilib_script_s;
 
@@ -25,8 +26,10 @@ struct pcilib_py_s {
     int py_initialized_inside; ///< Flag, shows that Py_Initialize has been called inside class
     struct pcilib_script_s *scripts;
 };
+#endif
 
 int pcilib_init_py(pcilib_t *ctx) {
+#ifdef BUILD_PYTHON_MODULES
     ctx->py = (pcilib_py_t*)malloc(sizeof(pcilib_py_t));
     if (!ctx->py) return PCILIB_ERROR_MEMORY;
 
@@ -53,6 +56,16 @@ int pcilib_init_py(pcilib_t *ctx) {
         return PCILIB_ERROR_FAILED;
 	
 	
+	
+	
+	ctx->py->scripts = NULL;
+#endif
+    return 0;
+}
+
+int pcilib_py_add_script_dir(pcilib_t *ctx)
+{
+#ifdef BUILD_PYTHON_MODULES
 	//create path string, where the model scripts should be
 	static int model_dir_added = 0;
 	if(!model_dir_added)
@@ -72,13 +85,12 @@ int pcilib_init_py(pcilib_t *ctx) {
 		free(model_path);
 		model_dir_added = 1;
 	}
-	
-	ctx->py->scripts = NULL;
-    return 0;
+#endif
+	return 0;
 }
 
 void pcilib_free_py(pcilib_t *ctx) {
-	
+#ifdef BUILD_PYTHON_MODULES
 	int py_initialized_inside = 0;
 	
     if (ctx->py) {		
@@ -92,6 +104,7 @@ void pcilib_free_py(pcilib_t *ctx) {
     
     if(py_initialized_inside)
 		Py_Finalize();
+#endif
 }
 
 /*
@@ -110,7 +123,7 @@ static int pcilib_py_realloc_string(pcilib_t *ctx, size_t required, size_t *size
     return 0;
 }
 */
-
+#ifdef BUILD_PYTHON_MODULES
 static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value) {
     int i;
     int err = 0;
@@ -216,8 +229,10 @@ static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_v
 
     return dst;
 }
+#endif
 
 int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value) {
+#ifdef BUILD_PYTHON_MODULES
     PyGILState_STATE gstate;
     char *code;
     PyObject* obj;
@@ -239,10 +254,15 @@ int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *va
 
     pcilib_debug(VIEWS, "Evaluating a Python string \'%s\' to %lf=\'%s\'", codestr, PyFloat_AsDouble(obj), code);
     return pcilib_set_value_from_float(ctx, value, PyFloat_AsDouble(obj));
+#else
+	pcilib_error("Current build not support python.");
+    return PCILIB_ERROR_NOTAVAILABLE;
+#endif
 }
 
 pcilib_py_object* pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *val, int *ret)
-{	
+{
+#ifdef BUILD_PYTHON_MODULES	
 	int err;
 	
 	switch(val->type)
@@ -292,10 +312,16 @@ pcilib_py_object* pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *va
             pcilib_error("Invalid register output type (unknown)");
 			return NULL;
 	}
+#else
+	pcilib_error("Current build not support python.");
+    if (ret) *ret = PCILIB_ERROR_NOTAVAILABLE;
+	return NULL;
+#endif
 }
 
 int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py_object* pyObjVal)
 {
+#ifdef BUILD_PYTHON_MODULES
 	PyObject* pyVal = pyObjVal;
 	int err;
 	
@@ -318,12 +344,18 @@ int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py
         return err;
         
     return 0;
+#else
+	pcilib_error("Current build not support python.");
+    return PCILIB_ERROR_NOTAVAILABLE;
+#endif
 }
 
-int pcilib_py_init_script(pcilib_t *ctx, char* module_name, pcilib_access_mode_t *mode)
-{	
+int pcilib_py_init_script(pcilib_t *ctx, const char* module_name)
+{
+#ifdef BUILD_PYTHON_MODULES
 	//extract module name from script name
-	char* py_module_name = strtok(module_name, ".");
+	char* py_module_name = strdup(module_name);
+	py_module_name = strtok(py_module_name, ".");
 	if(!py_module_name)
 	{
 		pcilib_error("Invalid script name specified in XML property (%s)."
@@ -336,26 +368,19 @@ int pcilib_py_init_script(pcilib_t *ctx, char* module_name, pcilib_access_mode_t
 	if(module)
 	{
 		pcilib_warning("Python module %s is already in hash. Skip init step", module_name);
-		mode[0] = module->mode;
 		return 0;
 	}
 	
-	//Initialize python module
-	if(!module_name)
-	{
-		pcilib_error("Invalid script name specified in XML property (NULL)");
-		return PCILIB_ERROR_INVALID_DATA;
-	}
-	
 	//import python script
 	PyObject* py_script_module = PyImport_ImportModule(py_module_name);
-	
 	if(!py_script_module)
 	{
 		printf("Error in import python module: ");
 		PyErr_Print();
+		free(py_module_name);
 		return PCILIB_ERROR_INVALID_DATA;
 	}
+	free(py_module_name);
 
 	//Initializing pcipywrap module if script use it
 	PyObject* dict = PyModule_GetDict(py_script_module);
@@ -380,45 +405,50 @@ int pcilib_py_init_script(pcilib_t *ctx, char* module_name, pcilib_access_mode_t
 	if (!module)
 		return PCILIB_ERROR_MEMORY;
 	module->module = py_script_module;
-	module->name = strdup(module_name);
-	if(!(module->name))
+	module->name = module_name;
+	HASH_ADD_STR( ctx->py->scripts, name, module);
+#endif
+	return 0;
+}
+
+int pcilib_py_get_transform_script_properties(pcilib_t *ctx, const char* module_name,
+pcilib_access_mode_t *mode)
+{
+#ifdef BUILD_PYTHON_MODULES
+	pcilib_script_s *module;
+	
+	HASH_FIND_STR(ctx->py->scripts, module_name, module);
+	if(!module)
 	{
-		free(module);
-		return PCILIB_ERROR_MEMORY;
+		pcilib_error("Failed to find script module (%s) in hash", module_name);
+		return PCILIB_ERROR_NOTFOUND;
 	}
-	sprintf(module->name, "%s", module_name);
-
 	
+	PyObject* dict = PyModule_GetDict(module->module);
 	//Setting correct mode
 	mode[0] = 0;
 	if(PyDict_Contains(dict, PyString_FromString("read_from_register")))
 		mode[0] |= PCILIB_ACCESS_R;	
 	if(PyDict_Contains(dict, PyString_FromString("write_to_register")))
-		mode[0] |= PCILIB_ACCESS_W;
-		
-	module->mode = mode[0];
-	HASH_ADD_STR( ctx->py->scripts, name, module);
-	
+		mode[0] |= PCILIB_ACCESS_W;	
 	return 0;
+#else
+	mode[0] = PCILIB_ACCESS_RW;
+	return 0;
+#endif
 }
 
-int pcilib_py_free_script(pcilib_t *ctx,char* module_name)
+int pcilib_py_free_script(pcilib_t *ctx, const char* module_name)
 {
+#ifdef BUILD_PYTHON_MODULES
 	pcilib_script_s *module;
 	HASH_FIND_STR(ctx->py->scripts, module_name, module);
 	
 	if(!module)
 	{
-		//For some reason it will crash if uncomment. printf same warning is ok
-		//pcilib_warning("Cant find Python module %s in hash. Seems it has already deleted.", module_name);
+		pcilib_warning("Cant find Python module %s in hash. Seems it has already deleted.", module_name);
 		return 0;
 	}
-	
-	if(module->name)
-	{
-		free(module->name);
-		module->name = NULL;
-	}
 		
 	if(module->module)
 	{
@@ -427,12 +457,14 @@ int pcilib_py_free_script(pcilib_t *ctx,char* module_name)
 	
 	HASH_DEL(ctx->py->scripts, module);
 	free(module);
+#endif
 	return 0;
 }
 
-int pcilib_script_run_func(pcilib_t *ctx, char* module_name,
+int pcilib_script_run_func(pcilib_t *ctx, const char* module_name,
                            const char* func_name,  pcilib_value_t *val)
-{	
+{
+#ifdef BUILD_PYTHON_MODULES
 	int err;
 	pcilib_script_s *module;
 	HASH_FIND_STR(ctx->py->scripts, module_name, module);
@@ -478,4 +510,8 @@ int pcilib_script_run_func(pcilib_t *ctx, char* module_name,
 		}
 	}
     return 0;
+#else
+	pcilib_error("Current build not support python.");
+    return PCILIB_ERROR_NOTAVAILABLE;
+#endif
 }

+ 8 - 3
pcilib/py.h

@@ -11,14 +11,19 @@ extern "C" {
 #endif
 
 int pcilib_init_py(pcilib_t *ctx);
+int pcilib_py_add_script_dir(pcilib_t *ctx);
 int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value);
 void pcilib_free_py(pcilib_t *ctx);
 
 
-int pcilib_py_init_script(pcilib_t *ctx, char* module_name, pcilib_access_mode_t *mode);
-int pcilib_py_free_script(pcilib_t *ctx,char* module_name);
-int pcilib_script_run_func(pcilib_t *ctx, char* module_name,
+int pcilib_py_init_script(pcilib_t *ctx, const char* module_name);
+int pcilib_py_free_script(pcilib_t *ctx, const char* module_name);
+int pcilib_script_run_func(pcilib_t *ctx, const char* module_name,
                            const char* func_name,  pcilib_value_t *val);
+                           
+int pcilib_py_get_transform_script_properties(pcilib_t *ctx,
+                                              const char* module_name,
+                                              pcilib_access_mode_t *mode);
 
 /*!
  * \brief Converts pcilib_value_t to PyObject.

+ 1 - 2
pcilib/xml.c

@@ -600,8 +600,7 @@ static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xp
             desc.write_to_reg = value;
             if ((value)&&(*value)) mode |= PCILIB_ACCESS_W;
         } else if (!strcasecmp(name, "script")) {
-			desc.module = strdup(value);
-			sprintf(desc.module, "%s", value);
+			desc.module = value;
 			break;
         }
     }

+ 2 - 3
pywrap/CMakeLists.txt

@@ -8,14 +8,13 @@ include_directories(
     ${UTHASH_INCLUDE_DIRS}
 )
 
+set(HEADERS pcipywrap.h)
+
 #Creating python wrapping
 INCLUDE(${SWIG_USE_FILE})
-
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
-
 SET(CMAKE_SWIG_FLAGS "")
 
-SET_SOURCE_FILES_PROPERTIES(pcipywrap.i PROPERTIES SWIG_FLAGS "-includeall")
 SWIG_ADD_MODULE(pcipywrap python pcipywrap.i pcipywrap.c)
 SWIG_LINK_LIBRARIES(pcipywrap ${PYTHON_LIBRARIES} pcilib)
 

+ 47 - 88
pywrap/pcipywrap.c

@@ -1,6 +1,4 @@
-#include "pci.h"
-#include "error.h"
-#include <Python.h>
+#include "pcipywrap.h"
 
 /*!
  * \brief Global pointer to pcilib_t context.
@@ -63,25 +61,11 @@ void pcilib_print_error_to_py(void *arg, const char *file, int line,
 	{
 		if(!full_log)
 			full_log = make_str("");
-    
-		if(strlen(buf_wrapped_message) >= 2 &&
-		   buf_wrapped_message[0] == '#' &&
-		   buf_wrapped_message[1] == 'E')
-		{
-			char* wrapped_exeption = make_str("%sprogramm error log:\n%s", &(buf_wrapped_message[2]), full_log);
-			free(full_log);
-			full_log = NULL;
 			
-			PyErr_SetString(PyExc_Exception, wrapped_exeption);
-			free(wrapped_exeption);
-		}
-		else
-		{
-			//copy received message to log
-			char* buf = full_log;
-			full_log = make_str("%s%s", buf, buf_wrapped_message);
-			free(buf);
-		}
+		//copy received message to log
+		char* buf = full_log;
+		full_log = make_str("%s%s", buf, buf_wrapped_message);
+		free(buf);
 	}
 	else
 		printf(buf_wrapped_message);
@@ -90,17 +74,35 @@ void pcilib_print_error_to_py(void *arg, const char *file, int line,
 	free(buf_raw_msg);
 }
 
-/*!
- * \brief Redirect pcilib standart log stream to exeption text.
- * Logger will accumulate errors untill get message, starts with "#E".
- * After that, logger will write last error, and all accumulated errors
- * to Python exeption text
- */
+void set_python_exception(const char* msg, ...)
+{
+	va_list vl;
+    va_start(vl, msg);
+	char *buf = vmake_str(msg, vl);
+	
+	char* wrapped_exeption;
+	if(full_log)
+		wrapped_exeption = make_str("%s\nprogramm error log:\n%s", buf, full_log);
+	else
+		wrapped_exeption = buf;
+	
+	free(full_log);
+	full_log = NULL;
+	
+	PyErr_SetString(PyExc_Exception, wrapped_exeption);
+	
+	free(buf);
+	if(full_log)
+		free(wrapped_exeption);
+	va_end(vl);
+}
+
+
 void __redirect_logs_to_exeption()
 {
-	pcilib_set_logger(pcilib_get_logger_min_prio(), 
+	pcilib_set_logger(pcilib_get_log_level(), 
 					  pcilib_print_error_to_py,
-					  pcilib_get_logger_argument());
+					  pcilib_get_logger_context());
 }
 
 /*!
@@ -112,27 +114,18 @@ void close_pcilib_instance(void *ctx)
 		pcilib_close(ctx);
 }
 
-/*!
- * \brief Wraps for pcilib_open function.
- * \param[in] fpga_device path to the device file [/dev/fpga0]
- * \param[in] model specifies the model of hardware, autodetected if NULL is passed
- * \return Pointer to pcilib_t, created by pcilib_open; NULL with exeption text, if failed.
- */
 PyObject* create_pcilib_instance(const char *fpga_device, const char *model)
 {
 	//opening device
     pcilib_t* ctx = pcilib_open(fpga_device, model);
     if(!ctx)
     {
-		pcilib_error("#E Failed pcilib_open(%s, %s)", fpga_device, model);
+		set_python_exception("Failed pcilib_open(%s, %s)", fpga_device, model);
 		return NULL;
 	}
 	return PyCObject_FromVoidPtr((void*)ctx, close_pcilib_instance);
 }
 
-/*!
- * \brief Closes current pciliv instance, if its open.
- */
 void close_curr_pcilib_instance()
 {
     if(__ctx)
@@ -142,25 +135,16 @@ void close_curr_pcilib_instance()
     }
 }
 
-/*!
- * \brief Returns current opened pcilib_t instatnce
- * \return Pointer to pcilib_t, serialized to bytearray
- */
 PyObject* get_curr_pcilib_instance()
 {
     return PyByteArray_FromStringAndSize((const char*)&__ctx, sizeof(pcilib_t*));
 }
 
-/*!
- * \brief Sets pcilib context to wraper.
- * \param[in] addr Pointer to pcilib_t, serialized to PyCObject
- * \return 1, serialized to PyObject or NULL with exeption text, if failed.
- */
 PyObject* set_pcilib(PyObject* addr)
 {
 	if(!PyCObject_Check(addr))
 	{
-        pcilib_error("#E Incorrect addr type. Only PyCObject is allowed");
+        set_python_exception("Incorrect addr type. Only PyCObject is allowed");
 		return NULL;
 	}
 	
@@ -169,18 +153,11 @@ PyObject* set_pcilib(PyObject* addr)
 	return PyInt_FromLong((long)1);
 }
 
-
-/*!
- * \brief Reads register value. Wrap for pcilib_read_register function.
- * \param[in] regname the name of the register
- * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
- * \return register value, can be integer or float type; NULL with exeption text, if failed.
- */
 PyObject* read_register(const char *regname, const char *bank)
 {
 	if(!__ctx)
 	{
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
 		return NULL;
 	}
 
@@ -192,27 +169,20 @@ PyObject* read_register(const char *regname, const char *bank)
 	err = pcilib_read_register(__ctx, bank, regname, &reg_value);
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_read_register");
+		set_python_exception("Failed pcilib_read_register");
 		return NULL;
 	}
 	
 	err = pcilib_set_value_from_register_value(__ctx, &val, reg_value);
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_set_value_from_register_value");
+		set_python_exception("Failed pcilib_set_value_from_register_value");
 		return NULL;
 	}
 
     return pcilib_get_value_as_pyobject(__ctx, &val, NULL);
 }
 
-/*!
- * \brief Writes value to register. Wrap for pcilib_write_register function.
- * \param[in] val Register value, that needs to be set. Can be int, float or string.
- * \param[in] regname the name of the register
- * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
- * \return 1, serialized to PyObject or NULL with exeption text, if failed.
- */
 PyObject* write_register(PyObject* val, const char *regname, const char *bank)
 {
 	if(!__ctx)
@@ -231,7 +201,7 @@ PyObject* write_register(PyObject* val, const char *regname, const char *bank)
 	
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_set_value_from_pyobject");
+		set_python_exception("Failed pcilib_set_value_from_pyobject");
 		return NULL;
 	}
 	
@@ -239,7 +209,7 @@ PyObject* write_register(PyObject* val, const char *regname, const char *bank)
 	reg_value = pcilib_get_value_as_register_value(__ctx, &val_internal, &err);
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_set_value_from_pyobject, (error %i)", err);
+		set_python_exception("Failed pcilib_set_value_from_pyobject, (error %i)", err);
 		return NULL;
 	}
 	
@@ -247,23 +217,18 @@ PyObject* write_register(PyObject* val, const char *regname, const char *bank)
 	
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_set_value_from_pyobject, (error %i)", err);
+		set_python_exception("Failed pcilib_set_value_from_pyobject, (error %i)", err);
 		return NULL;
 	}
 	
     return PyInt_FromLong((long)1);
 }
 
-/*!
- * \brief Reads propety value. Wrap for pcilib_get_property function.
- * \param[in] prop property name (full name including path)
- * \return property value, can be integer or float type; NULL with exeption text, if failed.
- */
 PyObject* get_property(const char *prop)
 {
 	if(!__ctx)
 	{
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
 		return NULL;
 	}
 	
@@ -274,26 +239,20 @@ PyObject* get_property(const char *prop)
 	
 	if(err)
 	{
-		pcilib_error("#E Failed pcilib_get_property, (error %i)", err);
+		set_python_exception("Failed pcilib_get_property, (error %i)", err);
 		return NULL;
 	}
 	
     return pcilib_get_value_as_pyobject(__ctx, &val, NULL);
 }
 
-/*!
- * \brief Writes value to property. Wrap for pcilib_set_property function.
- * \param[in] prop property name (full name including path)
- * \param[in] val Property value, that needs to be set. Can be int, float or string.
- * \return 1, serialized to PyObject or NULL with exeption text, if failed.
- */
 PyObject* set_property(PyObject* val, const char *prop)
 {
 	int err;
 	
 	if(!__ctx)
 	{
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
 		return NULL;
 	}
 	
@@ -301,14 +260,14 @@ PyObject* set_property(PyObject* val, const char *prop)
     err = pcilib_set_value_from_pyobject(__ctx, &val_internal, val);
 	if(err)
 	{
-		pcilib_error("#E pcilib_set_value_from_pyobject, (error %i)", err);
+		set_python_exception("pcilib_set_value_from_pyobject, (error %i)", err);
 		return NULL;
 	}
 	
 	err  = pcilib_set_property(__ctx, prop, &val_internal);
 	if(err)
 	{
-		pcilib_error("#E pcilib_set_property, (error %i)", err);
+		set_python_exception("pcilib_set_property, (error %i)", err);
 		return NULL;
 	}
 	
@@ -536,7 +495,7 @@ PyObject* get_registers_list(const char *bank)
 {
 	if(!__ctx)
 	{
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
 		return NULL;
 	}
 	
@@ -559,7 +518,7 @@ PyObject* get_register_info(const char* reg,const char *bank)
 {
     if(!__ctx)
     {
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
         return NULL;
     }
 
@@ -581,7 +540,7 @@ PyObject* get_property_list(const char* branch)
 {
     if(!__ctx)
     {
-        pcilib_error("#E pcilib_t handler not initialized");
+        set_python_exception("pcilib_t handler not initialized");
         return NULL;
     }
 

+ 4 - 0
pywrap/pcipywrap.i

@@ -1,5 +1,9 @@
 %module pcipywrap
 
+%{
+#include "pcipywrap.h"
+%}
+
 extern void __redirect_logs_to_exeption();
 
 extern PyObject* create_pcilib_instance(const char *fpga_device, const char *model = NULL);

+ 12 - 5
views/transform.c

@@ -68,12 +68,21 @@ pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_v
 	{	
 		pcilib_access_mode_t mode = 0;
 		
-		int err = pcilib_py_init_script(ctx, v_desc->module, &mode);
+		int err = pcilib_py_init_script(ctx, v_desc->module);
 		if(err)
 		{
-			pcilib_error("Failed init script module (%s) - error %i", v_desc->module, err);
+			pcilib_error("Failed init script module (%s) - error %i",
+			             v_desc->module, err);
 			return NULL;
-		} 
+		}
+		err = pcilib_py_get_transform_script_properties(ctx, v_desc->module,
+                                                        &mode);
+        if(err)
+		{
+			pcilib_error("Failed get transform script properties (%s) - error %i",
+			             v_desc->module, err);
+			return NULL;
+		}                                               
 		
 		v_desc->base.mode |= PCILIB_REGISTER_RW;
 		mode |= PCILIB_REGISTER_INCONSISTENT;
@@ -87,7 +96,5 @@ pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_v
     return view_ctx;
 }
 
-
-
 const pcilib_view_api_description_t pcilib_transform_view_api =
   { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read,  pcilib_transform_view_write };

+ 1 - 1
views/transform.h

@@ -9,7 +9,7 @@ typedef struct {
     pcilib_view_description_t base;
     const char *read_from_reg;			/**< Formula explaining how to convert the register value to the view value */
     const char *write_to_reg;			/**< Formula explaining how to convert from the view value to the register value */
-	char *module; /**< Python script module name (without extension) */
+	const char *module; /**< Python script module name (without extension) */
 } pcilib_transform_view_description_t;
 
 #ifndef _PCILIB_VIEW_TRANSFORM_C