16 #include "notifyCategory.h" 17 #include "configPageManager.h" 18 #include "configVariableFilename.h" 19 #include "configVariableBool.h" 21 #include "config_prc.h" 30 #include <android/log.h> 43 _owns_ostream_ptr =
false;
44 _null_ostream_ptr =
new fstream;
46 _assert_handler = (AssertHandler *)NULL;
47 _assert_failed =
false;
57 if (_owns_ostream_ptr) {
60 delete _null_ostream_ptr;
74 if (_owns_ostream_ptr && ostream_ptr != _ostream_ptr) {
78 if (ostream_ptr == (ostream *)NULL) {
80 _owns_ostream_ptr =
false;
82 _ostream_ptr = ostream_ptr;
83 _owns_ostream_ptr = delete_later;
114 static bool got_flag =
false;
115 static ios_fmtflags flag;
118 #ifndef PHAVE_IOSTREAM 119 flag = ios::bitalloc();
123 flag = (ios_fmtflags)0;
149 _assert_handler = assert_handler;
160 _assert_handler = (AssertHandler *)NULL;
171 return (_assert_handler != (AssertHandler *)NULL);
182 return _assert_handler;
208 nassertr(basename.find(
':') == string::npos, (
NotifyCategory *)NULL);
212 fullname = parent_category->get_fullname() +
":" + basename;
218 if (!basename.empty()) {
220 fullname =
":" + basename;
224 pair<Categories::iterator, bool> result =
225 _categories.insert(Categories::value_type(fullname, (
NotifyCategory *)NULL));
227 bool inserted = result.second;
234 category =
new NotifyCategory(fullname, basename, parent_category);
268 Categories::const_iterator ci;
269 ci = _categories.find(fullname);
270 if (ci != _categories.end()) {
277 string basename = fullname;
279 size_t colon = fullname.rfind(
':');
280 if (colon != string::npos) {
281 parent_category =
get_category(fullname.substr(0, colon));
282 basename = fullname.substr(colon + 1);
284 }
else if (!fullname.empty()) {
302 return *(
ptr()->_ostream_ptr);
314 return *(
ptr()->_null_ostream_ptr);
327 out() << str <<
"\n";
338 if (_global_ptr == (
Notify *)NULL) {
361 const char *source_file) {
381 const char *source_file) {
384 << expression <<
" at line " << line <<
" of " << source_file;
385 string message = message_str.str();
387 if (!_assert_failed) {
390 _assert_failed =
true;
391 _assert_error_message = message;
395 return (*_assert_handler)(expression, line, source_file);
399 __android_log_assert(
"assert",
"Panda3D",
"Assertion failed: %s", message.c_str());
401 nout <<
"Assertion failed: " << message <<
"\n";
427 int *
ptr = (
int *)NULL;
450 for (string::const_iterator si = str.begin();
453 lstring += tolower(*si);
456 if (lstring ==
"spam") {
459 }
else if (lstring ==
"debug") {
462 }
else if (lstring ==
"info") {
465 }
else if (lstring ==
"warning") {
468 }
else if (lstring ==
"error") {
471 }
else if (lstring ==
"fatal") {
475 return NS_unspecified;
490 static bool already_initialized =
false;
491 if (already_initialized) {
492 nout <<
"Notify::config_initialized() called more than once.\n";
495 already_initialized =
true;
497 if (_ostream_ptr == &cerr) {
499 (
"notify-output",
"",
500 "The filename to which to write all the output of notify");
502 if (!notify_output.empty()) {
503 if (notify_output ==
"stdout") {
504 cout.setf(ios::unitbuf);
507 }
else if (notify_output ==
"stderr") {
518 int logfile_fd = open(os_specific.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
519 if (logfile_fd < 0) {
520 nout <<
"Unable to open file " << filename <<
" for output.\n";
522 dup2(logfile_fd, STDOUT_FILENO);
523 dup2(logfile_fd, STDERR_FILENO);
529 pofstream *
out =
new pofstream;
531 nout <<
"Unable to open file " << filename <<
" for output.\n";
534 out->setf(ios::unitbuf);
537 #endif // BUILD_IPHONE ostream * get_ostream_ptr() const
Returns the system-wide ostream for all Notify messages.
void set_assert_handler(AssertHandler *assert_handler)
Sets a pointer to a C function that will be called when an assertion test fails.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
This is a convenience class to specialize ConfigVariable as a Filename type.
This is a convenience class to specialize ConfigVariable as a boolean type.
void set_text()
Indicates that the filename represents a text file.
NotifyCategory * get_top_category()
Returns the topmost Category in the hierarchy.
static ostream & out()
A convenient way to get the ostream that should be written to for a Notify-type message.
static Notify * ptr()
Returns the pointer to the global Notify object.
A particular category of error messages.
void clear_assert_handler()
Removes the installed assert handler and restores default behavior of nassertr() and nassertv()...
static ostream & null()
A convenient way to get an ostream that doesn't do anything.
NotifyCategory * get_category(const string &basename, NotifyCategory *parent_category)
Finds or creates a new Category given the basename of the category and its parent in the category hie...
AssertHandler * get_assert_handler() const
Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise...
The name of a file, such as a texture file or an Egg file.
bool has_assert_handler() const
Returns true if a user assert handler has been installed, false otherwise.
void set_ostream_ptr(ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.
bool assert_failure(const string &expression, int line, const char *source_file)
This function is not intended to be called directly by user code.
static ios_fmtflags get_literal_flag()
Returns a flag that may be set on the Notify stream via setf() that, when set, enables "literal" mode...
void config_initialized()
Intended to be called only by Config, this is a callback that indicates to Notify when Config has don...
static void write_string(const string &str)
A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify...
static NotifySeverity string_severity(const string &string)
Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level...
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
An object that handles general error reporting to the user.