Oolite
Loading...
Searching...
No Matches
OODebugStandards.m
Go to the documentation of this file.
1/*
2
3OODebugStandards.m
4
5OXP strictness warnings for errors and deprecated content
6
7
8Copyright (C) 2014
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30#import "OODebugStandards.h"
31#import "GameController.h"
33#import "OOLogging.h"
34
35#ifndef OO_DEBUG_MONITOR_ENABLED
36// in release mode, stubs
37void OOStandardsDeprecated(NSString* message) { }
38void OOStandardsError(NSString* message) { }
39BOOL OOEnforceStandards() { return NO; }
41
42#else
43
44void OOStandardsSetup(void);
45void OOStandardsInternal(NSString* type, NSString* message);
46
47static BOOL sSetup = NO;
48
49typedef enum {
50 // do nothing (equivalent to release build)
51 STANDARDS_ENFORCEMENT_OFF = 0,
52 // warn in log but otherwise do nothing
53 STANDARDS_ENFORCEMENT_WARN,
54 // warn in log, block use of deprecated or error items
55 STANDARDS_ENFORCEMENT_ENFORCE,
56 // note in log, then exit if deprecated or error condition occurs
57 STANDARDS_ENFORCEMENT_QUIT
58} OOStandardsEnforcement;
59
60// Deployment builds stay quiet unless an OXP developer opts in with enforce-oxp-standards.
61#ifdef NDEBUG
62#define STANDARDS_ENFORCEMENT_DEFAULT STANDARDS_ENFORCEMENT_OFF
63#else
64#define STANDARDS_ENFORCEMENT_DEFAULT STANDARDS_ENFORCEMENT_WARN
65#endif
66
67static OOStandardsEnforcement sEnforcement = STANDARDS_ENFORCEMENT_DEFAULT;
68
69void OOStandardsSetup()
70{
71 if (sSetup) {
72 return;
73 }
74 NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
75 int s = [prefs oo_intForKey:@"enforce-oxp-standards"
76 defaultValue:STANDARDS_ENFORCEMENT_DEFAULT];
77 if (s < STANDARDS_ENFORCEMENT_OFF) {
78 s = STANDARDS_ENFORCEMENT_OFF;
79 } else if (s > STANDARDS_ENFORCEMENT_QUIT) {
80 s = STANDARDS_ENFORCEMENT_QUIT;
81 }
82 sEnforcement = s;
83}
84
85void OOStandardsInternal(NSString* type, NSString* message)
86{
87 OOStandardsSetup();
88 if (sEnforcement == STANDARDS_ENFORCEMENT_OFF) {
89 return;
90 }
91
92 OOLog(type, @"%@", message);
93
94 if (sEnforcement == STANDARDS_ENFORCEMENT_QUIT) {
96 // exit
97 }
98}
99
100void OOStandardsDeprecated(NSString* message)
101{
102 OOStandardsInternal(@"oxp-standards.deprecated", message);
103}
104
105void OOStandardsError(NSString* message)
106{
107 OOStandardsInternal(@"oxp-standards.error", message);
108}
109
111{
112 OOStandardsSetup();
113 return sEnforcement >= STANDARDS_ENFORCEMENT_ENFORCE;
114}
115
117{
118 sEnforcement = STANDARDS_ENFORCEMENT_WARN;
119 sSetup = YES;
120}
121
122#endif
BOOL OOEnforceStandards()
void OOStandardsDeprecated(NSString *message)
void OOSetStandardsForOXPVerifierMode()
void OOStandardsError(NSString *message)
#define OOLog(class, format,...)
Definition OOLogging.h:84
GameController * sharedController()
void exitAppWithContext:(NSString *context)