source: cpp/frams/errmgr/errmanager.cpp @ 201

Last change on this file since 201 was 197, checked in by Maciej Komosinski, 11 years ago

GDK used by developers since 1999, distributed on the web since 2002

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