source: cpp/gdk/errmanager.cpp @ 72

Last change on this file since 72 was 66, checked in by Maciej Komosinski, 14 years ago

set 'eol-style' to 'native'

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// This file is a part of the Framsticks GDK library.
2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "errmanager.h"
6
7ErrorManager globalErrorManager;
8
9void FramMessage(const char *o,const char *m,const char *bl,int w)
10{
11globalErrorManager.send(o,m,bl,w);
12}
13
14void ErrorManager::send(int level,const char *o,const char *m,const char *bl,int w)
15{
16if (level>=handlers.size()) level=handlers.size()-1;
17bool blocked=0;
18for(int i=level;i>=0;i--)
19        {
20        ErrorHandlerBase *r=handlers(i);
21        if ((!blocked)||(r->options & ErrorHandlerBase::CannotBeBlocked))
22                r->handle(o,m,bl,w);
23        if (!(r->options & ErrorHandlerBase::DontBlock)) blocked=1;
24        }
25}
26
27int ErrorManager::add(ErrorHandlerBase *h)
28{
29h->mgr=this;
30handlers+=h;
31return handlers.size()-1;
32}
33
34void ErrorManager::remove(int i)
35{
36ErrorHandlerBase *h=handlers(i);
37h->mgr=0;
38handlers.remove(i);
39}
40
41void ErrorManager::remove(ErrorHandlerBase *h)
42{
43int i;
44if ((i=handlers.find(h))<0) return;
45remove(i);
46}
47
48void ErrorManager::removeAll()
49{
50while(handlers.size()>0)
51        remove(handlers.size()-1);
52}
53
54//////////////////////////////////
55
56void ErrorHandlerBase::send(const char *o,const char *m,const char *bl,int w)
57{
58if (!isEnabled()) return;
59int level=mgr->find(this);
60if (level>=0) mgr->send(level-1,o,m,bl,w);
61}
62
63void ErrorHandlerBase::FMprintf(const char *o,const char *m,int w,const char *bl, ...)
64{
65if (!isEnabled()) return;
66char buf[10000];
67va_list argptr;
68va_start(argptr,bl);
69vsnprintf(buf,10000,bl,argptr);
70va_end(argptr);
71send(o,m,buf,w);
72}
73
74
75void ErrorHandlerBase::enable()
76{
77if (isEnabled()) return;
78globalErrorManager.add(this);
79}
80
81void ErrorHandlerBase::disable()
82{
83if (!isEnabled()) return;
84globalErrorManager.remove(this);
85}
86
87/////////////////////////////////
88
89void ErrorHandler::handle(const char *o,const char *m,const char *bl,int w)
90{
91if (w>maxlevel) maxlevel=w;
92if (w>=FMLV_INFO) infocount++;
93if (w>=FMLV_WARN) warncount++;
94if (w>=FMLV_ERROR) errcount++;
95
96if (w>=storlevel)
97        {
98        storcount++;
99        if (options & (StoreFirstMessage|StoreAllMessages))
100                {
101                if (!((options&StoreFirstMessage)&&(msgs.len()>0)))
102                        {
103                        if (msgs.len()>0) msgs+='\n';
104                        msgs+=o; msgs+="::"; msgs+=m;
105                        msgs+=" - "; msgs+=bl;
106                        }
107                }
108        }
109}
Note: See TracBrowser for help on using the repository browser.