Revision: 17935
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17935
Author:   blendix
Date:     2008-12-19 01:50:21 +0100 (Fri, 19 Dec 2008)

Log Message:
-----------
2.5: Change blenloader module to use the Report system for reporting errors.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_report.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/report.c
    branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h
    branches/blender2.5/blender/source/blender/blenloader/BLO_writefile.h
    branches/blender2.5/blender/source/blender/blenloader/intern/readblenentry.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.h
    branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_fileglobal_types.h
    branches/blender2.5/blender/source/blender/readblenfile/BLO_readblenfile.h
    
branches/blender2.5/blender/source/blender/readblenfile/intern/BLO_readblenfile.c
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c
    
branches/blender2.5/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    
branches/blender2.5/blender/source/gameengine/GamePlayer/ActiveX/BlenderPlayerCtl.cpp
    
branches/blender2.5/blender/source/gameengine/GamePlayer/common/GPC_Engine.cpp
    branches/blender2.5/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
    
branches/blender2.5/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_engine_data_wraps.h
    
branches/blender2.5/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_ketsji_hooks.cpp

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_report.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_report.h  
2008-12-19 00:43:37 UTC (rev 17934)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_report.h  
2008-12-19 00:50:21 UTC (rev 17935)
@@ -48,7 +48,8 @@
 
 enum ReportListFlags {
        RPT_PRINT = 1,
-       RPT_STORE = 2
+       RPT_STORE = 2,
+       RPT_HAS_ERROR = 4
 };
 
 typedef struct Report {
@@ -60,21 +61,25 @@
 
 typedef struct ReportList {
        ListBase list;
-       ReportType level;
-       int flags;
+       ReportType printlevel;
+       ReportType storelevel;
+       int flag;
 } ReportList;
 
-void BKE_report_list_init(ReportList *reports, int flag);
-void BKE_report_list_clear(ReportList *reports);
+void BKE_reports_init(ReportList *reports, int flag);
+void BKE_reports_clear(ReportList *reports);
 
 void BKE_report(ReportList *reports, ReportType type, const char *message);
 void BKE_reportf(ReportList *reports, ReportType type, const char *format, 
...);
 
-ReportType BKE_report_level(ReportList *reports);
-void BKE_report_level_set(ReportList *reports, ReportType level);
+ReportType BKE_report_print_level(ReportList *reports);
+void BKE_report_print_level_set(ReportList *reports, ReportType level);
 
-int BKE_report_has_error(ReportList *reports);
+ReportType BKE_report_store_level(ReportList *reports);
+void BKE_report_store_level_set(ReportList *reports, ReportType level);
 
+void BKE_reports_print(ReportList *reports, ReportType level);
+
 #ifdef __cplusplus
 }
 #endif

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c      
2008-12-19 00:43:37 UTC (rev 17934)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/blender.c      
2008-12-19 00:50:21 UTC (rev 17935)
@@ -77,6 +77,7 @@
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_object.h"
+#include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_sound.h"
@@ -435,11 +436,13 @@
 
 int BKE_read_file(bContext *C, char *dir, void *unused) 
 {
-       BlendReadError bre;
+       ReportList reports;
        BlendFileData *bfd;
        int retval= 1;
        
-       bfd= BLO_read_from_file(dir, &bre);
+       BKE_reports_init(&reports, RPT_STORE);
+
+       bfd= BLO_read_from_file(dir, &reports);
        if (bfd) {
                if(bfd->user) retval= 2;
                
@@ -450,38 +453,48 @@
        else {
 // XXX         error("Loading %s failed: %s", dir, BLO_bre_as_string(bre));
        }
+
+       BKE_reports_clear(&reports);
                
        return (bfd?retval:0);
 }
 
 int BKE_read_file_from_memory(bContext *C, char* filebuf, int filelength, void 
*unused)
 {
-       BlendReadError bre;
+       ReportList reports;
        BlendFileData *bfd;
-                       
-       bfd= BLO_read_from_memory(filebuf, filelength, &bre);
+
+       BKE_reports_init(&reports, RPT_STORE);
+
+       bfd= BLO_read_from_memory(filebuf, filelength, &reports);
        if (bfd) {
                setup_app_data(C, bfd, "<memory2>");
        } else {
 // XXX         error("Loading failed: %s", BLO_bre_as_string(bre));
        }
                
+       BKE_reports_clear(&reports);
+
        return (bfd?1:0);
 }
 
 /* memfile is the undo buffer */
 int BKE_read_file_from_memfile(bContext *C, MemFile *memfile)
 {
-       BlendReadError bre;
+       ReportList reports;
        BlendFileData *bfd;
        
-       bfd= BLO_read_from_memfile(G.sce, memfile, &bre);
+       BKE_reports_init(&reports, RPT_STORE);
+
+       bfd= BLO_read_from_memfile(G.sce, memfile, &reports);
        if (bfd) {
                setup_app_data(C, bfd, "<memory1>");
        } else {
 // XXX         error("Loading failed: %s", BLO_bre_as_string(bre));
        }
                
+       BKE_reports_clear(&reports);
+
        return (bfd?1:0);
 }
 
@@ -568,8 +581,9 @@
 
        /* disk save version */
        if(UNDO_DISK) {
+               ReportList reports;
                static int counter= 0;
-               char *err, tstr[FILE_MAXDIR+FILE_MAXFILE];
+               char tstr[FILE_MAXDIR+FILE_MAXFILE];
                char numstr[32];
                
                /* calculate current filename */
@@ -579,18 +593,22 @@
                sprintf(numstr, "%d.blend", counter);
                BLI_make_file_string("/", tstr, btempdir, numstr);
        
-               success= BLO_write_file(C, tstr, G.fileflags, &err);
+               BKE_reports_init(&reports, 0);
+               success= BLO_write_file(C, tstr, G.fileflags, &reports);
+               BKE_reports_clear(&reports);
                
                strcpy(curundo->str, tstr);
        }
        else {
+               ReportList reports;
                MemFile *prevfile=NULL;
-               char *err;
                
                if(curundo->prev) prevfile= &(curundo->prev->memfile);
                
                memused= MEM_get_memory_in_use();
-               success= BLO_write_file_mem(C, prevfile, &curundo->memfile, 
G.fileflags, &err);
+               BKE_reports_init(&reports, 0);
+               success= BLO_write_file_mem(C, prevfile, &curundo->memfile, 
G.fileflags, &reports);
+               BKE_reports_clear(&reports);
                curundo->undosize= MEM_get_memory_in_use() - memused;
        }
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/report.c       
2008-12-19 00:43:37 UTC (rev 17934)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/report.c       
2008-12-19 00:50:21 UTC (rev 17935)
@@ -57,15 +57,16 @@
        }
 }
 
-void BKE_report_list_init(ReportList *reports, int flags)
+void BKE_reports_init(ReportList *reports, int flag)
 {
        memset(reports, 0, sizeof(ReportList));
 
-       reports->level= RPT_WARNING;
-       reports->flags= flags;
+       reports->storelevel= RPT_WARNING;
+       reports->printlevel= RPT_WARNING;
+       reports->flag= flag;
 }
 
-void BKE_report_list_clear(ReportList *reports)
+void BKE_reports_clear(ReportList *reports)
 {
        Report *report;
 
@@ -80,15 +81,18 @@
        Report *report;
        int len;
 
-       if(!reports || type < reports->level)
+       if(!reports)
                return;
+       
+       if(type >= RPT_ERROR)
+               reports->flag |= RPT_HAS_ERROR;
 
-       if(reports->flags & RPT_PRINT) {
+       if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) {
                printf("%s: %s\n", report_type_str(type), message);
                fflush(stdout); /* this ensures the message is printed before a 
crash */
        }
 
-       if(reports->flags & RPT_STORE) {
+       if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
                report= MEM_callocN(sizeof(Report), "Report");
                report->type= type;
                report->typestr= report_type_str(type);
@@ -108,17 +112,20 @@
        char *message;
        int len= 256, maxlen= 65536, retval;
 
-       if(!reports || type < reports->level)
+       if(!reports)
                return;
 
-       if(reports->flags & RPT_PRINT) {
+       if(type >= RPT_ERROR)
+               reports->flag |= RPT_HAS_ERROR;
+
+       if((reports->flag & RPT_PRINT) && (type >= reports->printlevel)) {
                va_start(args, format);
                vprintf(format, args);
                va_end(args);
                fflush(stdout); /* this ensures the message is printed before a 
crash */
        }
 
-       if(reports->flags & RPT_STORE) {
+       if((reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
                while(1) {
                        message= MEM_callocN(sizeof(char)*len+1, 
"ReportMessage");
 
@@ -160,27 +167,37 @@
        }
 }
 
-ReportType BKE_report_level(ReportList *reports)
+ReportType BKE_report_print_level(ReportList *reports)
 {
-       return reports->level;
+       return reports->printlevel;
 }
 
-void BKE_report_level_set(ReportList *reports, ReportType level)
+void BKE_report_print_level_set(ReportList *reports, ReportType level)
 {
-       reports->level= level;
+       reports->printlevel= level;
 }
 
-int BKE_report_has_error(ReportList *reports)
+ReportType BKE_report_store_level(ReportList *reports)
 {
+       return reports->storelevel;
+}
+
+void BKE_report_store_level_set(ReportList *reports, ReportType level)
+{
+       reports->storelevel= level;
+}
+
+void BKE_reports_print(ReportList *reports, ReportType level)
+{
        Report *report;
 
        if(!reports)
-               return 0;
+               return;
+       
+       for(report=reports->list.first; report; report=report->next)
+               if(report->type >= level)
+                       printf("%s: %s\n", report->typestr, report->message);
 
-       for(report=reports->list.first; report; report=report->next)
-               if(report->type >= RPT_ERROR)
-                       return 1;
-       
-       return 0;
+       fflush(stdout);
 }
 

Modified: branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h        
2008-12-19 00:43:37 UTC (rev 17934)
+++ branches/blender2.5/blender/source/blender/blenloader/BLO_readfile.h        
2008-12-19 00:50:21 UTC (rev 17935)
@@ -34,16 +34,17 @@
 extern "C" {
 #endif
 
-struct SpaceFile;
-struct SpaceImaSel;
+struct bScreen;
+struct direntry;
 struct FileList;
 struct LinkNode;
 struct Main;
-struct UserDef;
-struct bScreen;
-struct Scene;
 struct MemFile;
-struct direntry;
+struct ReportList;
+struct Scene;
+struct SpaceFile;
+struct SpaceImaSel;
+struct UserDef;
 
 typedef struct BlendHandle     BlendHandle;
 
@@ -53,29 +54,6 @@
        BLENFILETYPE_RUNTIME= 3
 } BlenFileType;
 
-typedef enum {
-       BRE_NONE, 
-       
-       BRE_UNABLE_TO_OPEN, 
-       BRE_UNABLE_TO_READ, 
-
-       BRE_OUT_OF_MEMORY, 
-       BRE_INTERNAL_ERROR, 
-
-       BRE_NOT_A_BLEND, 
-       BRE_NOT_A_PUBFILE,
-       BRE_INCOMPLETE, 
-       BRE_CORRUPT, 
-       
-       BRE_TOO_NEW, 
-       BRE_NOT_ALLOWED, 
-       
-       BRE_NO_SCREEN, 
-       BRE_NO_SCENE, 
-       
-       BRE_INVALID
-} BlendReadError;
-
 typedef struct BlendFileData {
        struct Main*    main;
        struct UserDef* user;
@@ -93,48 +71,35 @@
 
        /**
         * Open a blender file from a pathname. The function
-        * returns NULL and sets the @a error_r argument if
+        * returns NULL and sets a report in the list if
         * it cannot open the file.
         * 
         * @param file The path of the file to open.
-        * @param error_r If the return value is NULL, an error
-        * code indicating the cause of the failure.
+        * @param reports If the return value is NULL, errors
+        * indicating the cause of the failure.
         * @return The data of the file.
         */
-BlendFileData* BLO_read_from_file              (char *file, BlendReadError 
*error_r);
+BlendFileData* BLO_read_from_file              (char *file, struct ReportList 
*reports);
 
        /**
         * Open a blender file from memory. The function
-        * returns NULL and sets the @a error_r argument if
+        * returns NULL and sets a report in the list if
         * it cannot open the file.
         * 
         * @param mem The file data.
         * @param memsize The length of @a mem.
-        * @param error_r If the return value is NULL, an error
-        * code indicating the cause of the failure.
+        * @param reports If the return value is NULL, errors
+        * indicating the cause of the failure.
         * @return The data of the file.
         */
-BlendFileData* BLO_read_from_memory(void *mem, int memsize, BlendReadError 
*error_r);
+BlendFileData* BLO_read_from_memory(void *mem, int memsize, struct ReportList 
*reports);
 
 /**
  * file name is current file, only for retrieving library data */
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to