macros.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * $Id: macros.h,v 1.2 2010/01/25 18:50:10 astra Exp $
18  */
19 
20 #ifndef _MACROS_H
21 #define _MACROS_H
22 
23 
24 #include "exception.h"
25 #include "config.h"
26 
27 #define bool int
28 #define true 1
29 #define false 0
30 #define null 0
31 
32 #define PROXY(o) (o->this)
33 #define MIN(i,j) (i < j ? i : j)
34 #if !constant(steamtools.get_caller)
35 #define CALLER Caller.get_caller(this_object(), backtrace())
36 #else
37 #define CALLER steamtools.get_caller(this_object())
38 #endif
39 #define MCALLER (CALLER == master() ? PREVCALLER : CALLER)
40 
41 #define PREVCALLER function_object(backtrace()[-3][2])
42 
43 #define CALLINGFUNCTION function_name(backtrace()[-2][2])
44 
45 #define CALLERCLASS backtrace()[-2][0]
46 
47 #define CALLERPROGRAM object_program(function_object(backtrace()[-2][2]))
48 
49 #define MESSAGE(s, args...) write("["+Calendar.Second(time())->format_time()+"] "+s+"\n", args)
50 #define MESSAGE_START(s, args...) write("["+Calendar.Second(time())->format_time()+"] "+s, args)
51 #define MESSAGE_APPEND(s, args...) write(s, args)
52 #define MESSAGE_END(s, args...) write(s+"\n", args)
53 
54 #define WARN(s, args...) werror(s+"\n", args)
55 
56 #ifdef DEBUG
57 #define LOG(s) werror(s+"\n")
58 #else
59 #define LOG(s)
60 #endif
61 
62 #define FATAL(s, args...) werror("-------------------------------\n"+ctime(time())+s+"\n", args)
63 
64 #define _LOG(s) werror("("+this_object()->get_object_id()+") "+s+"\n")
65 
66 #ifdef DEBUG
67 #define TRACE(s) werror("["+master()->stupid_describe(this_object())+"]"+s+"\n")
68 #else
69 #define TRACE(s)
70 #endif
71 
72 #define LOG_DB(s) catch {_Server->get_module("log")->log_text("database",s); }
73 //#define LOG_DB
74 
75 //#define LOG_DB(s) werror("DB:"+s+"\n")
76 
77 #ifdef DEBUG_SECURITY
78 #define SECURITY_LOG(s, args...) if (1) {if (_Server->get_module("log")) _Server->get_module("log")->log_security(s, args);}
79 #else
80 #define SECURITY_LOG(s, args...)
81 #endif
82 
83 #define LOG_BOOT(s) catch { _LOG->log_boot(s); }
84 
85 #define LOG_EVENT(s) catch{_LOG->log_event(s);}
86 
87 #define LOG_ERR(s) catch{_LOG->log_error(s);}
88 
89 #define LOG_DEBUG(s) catch{_Server->get_module("log")->log_debug(s);}
90 #define PRINT_BT(c) ("Error: " + c[0] + "\n" + master()->describe_backtrace(c[1]))
91 
92 #define THROW(c, e) throw( ({ c, backtrace(), e}))
93 #define IS_SOCKET(o) (master()->is_socket(o))
94 
95 #define NIL (([])[""])
96 
97 #define CONTENTOF(x) _FILEPATH->path_to_object(x)->get_content()
98 
99 #define T_INT "int"
100 #define T_STRING "string"
101 #define T_FLOAT "float"
102 #define T_OBJECT "object"
103 #define T_MAPPING "mapping"
104 #define T_ARRAY "array"
105 
106 
107 
108 #define IS_PROXY(o) (object_program(o) == (program)"/kernel/proxy.pike" || object_program(o) == (program)"/kernel/proxy")
109 
110 #define URLTYPE_FS 0
111 #define URLTYPE_DB 1
112 #define URLTYPE_HTTP 2
113 #define URLTYPE_RELOC 3
114 #define URLTYPE_DBO 4
115 #define URLTYPE_DBFT 5
116 
117 #define MAX_BUFLEN 65504
118 
119 #endif