29 #include <android/log.h> 35 using std::ostringstream;
38 Notify *Notify::_global_ptr =
nullptr;
45 _ostream_ptr = &std::cerr;
46 _owns_ostream_ptr =
false;
47 _null_ostream_ptr =
new std::fstream;
49 _assert_handler =
nullptr;
50 _assert_failed =
false;
58 if (_owns_ostream_ptr) {
61 delete _null_ostream_ptr;
72 if (_owns_ostream_ptr && ostream_ptr != _ostream_ptr) {
76 if (ostream_ptr ==
nullptr) {
78 _owns_ostream_ptr =
false;
80 _ostream_ptr = ostream_ptr;
81 _owns_ostream_ptr = delete_later;
105 static bool got_flag =
false;
106 static ios_fmtflags flag;
109 #ifndef PHAVE_IOSTREAM 110 flag = std::ios::bitalloc();
114 flag = (ios_fmtflags)0;
135 _assert_handler = assert_handler;
144 _assert_handler =
nullptr;
152 return (_assert_handler !=
nullptr);
161 return _assert_handler;
181 nassertr(basename.find(
':') == string::npos,
nullptr);
184 if (parent_category !=
nullptr) {
185 fullname = parent_category->get_fullname() +
":" + basename;
190 if (!basename.empty()) {
192 fullname =
":" + basename;
196 std::pair<Categories::iterator, bool> result =
197 _categories.insert(Categories::value_type(fullname,
nullptr));
199 bool inserted = result.second;
205 category =
new NotifyCategory(fullname, basename, parent_category);
231 Categories::const_iterator ci;
232 ci = _categories.find(fullname);
233 if (ci != _categories.end()) {
240 string basename = fullname;
242 size_t colon = fullname.rfind(
':');
243 if (colon != string::npos) {
244 parent_category =
get_category(fullname.substr(0, colon));
245 basename = fullname.substr(colon + 1);
247 }
else if (!fullname.empty()) {
262 return *(
ptr()->_ostream_ptr);
271 return *(
ptr()->_null_ostream_ptr);
281 out() << str <<
"\n";
290 if (_global_ptr ==
nullptr) {
309 const char *source_file) {
325 const char *source_file) {
326 ostringstream message_str;
328 << expression <<
" at line " << line <<
" of " << source_file;
329 string message = message_str.str();
331 if (!_assert_failed) {
334 _assert_failed =
true;
335 _assert_error_message = message;
339 return (*_assert_handler)(expression, line, source_file);
343 __android_log_assert(
"assert",
"Panda3D",
"Assertion failed: %s", message.c_str());
345 nout <<
"Assertion failed: " << message <<
"\n";
389 for (string::const_iterator si = str.begin();
392 lstring += (char)tolower(*si);
395 if (lstring ==
"spam") {
398 }
else if (lstring ==
"debug") {
401 }
else if (lstring ==
"info") {
404 }
else if (lstring ==
"warning") {
407 }
else if (lstring ==
"error") {
410 }
else if (lstring ==
"fatal") {
414 return NS_unspecified;
425 static bool already_initialized =
false;
426 if (already_initialized) {
427 nout <<
"Notify::config_initialized() called more than once.\n";
430 already_initialized =
true;
432 if (_ostream_ptr == &cerr) {
434 (
"notify-output",
"",
435 "The filename to which to write all the output of notify");
437 if (!notify_output.empty()) {
438 if (notify_output ==
"stdout") {
439 cout.setf(std::ios::unitbuf);
442 }
else if (notify_output ==
"stderr") {
452 int logfile_fd = open(os_specific.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
453 if (logfile_fd < 0) {
454 nout <<
"Unable to open file " << filename <<
" for output.\n";
456 dup2(logfile_fd, STDOUT_FILENO);
457 dup2(logfile_fd, STDERR_FILENO);
463 pofstream *
out =
new pofstream;
465 nout <<
"Unable to open file " << filename <<
" for output.\n";
468 out->setf(std::ios::unitbuf);
471 #endif // BUILD_IPHONE std::ostream * get_ostream_ptr() const
Returns the system-wide ostream for all Notify messages.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
void set_assert_handler(AssertHandler *assert_handler)
Sets a pointer to a C function that will be called when an assertion test fails.
This is a convenience class to specialize ConfigVariable as a Filename type.
This is a convenience class to specialize ConfigVariable as a boolean type.
NotifyCategory * get_category(const std::string &basename, NotifyCategory *parent_category)
Finds or creates a new Category given the basename of the category and its parent in the category hie...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_text()
Indicates that the filename represents a text file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NotifyCategory * get_top_category()
Returns the topmost Category in the hierarchy.
static std::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.
static void write_string(const std::string &str)
A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear_assert_handler()
Removes the installed assert handler and restores default behavior of nassertr() and nassertv().
static std::ostream & null()
A convenient way to get an ostream that doesn't do anything.
AssertHandler * get_assert_handler() const
Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
bool assert_failure(const std::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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static NotifySeverity string_severity(const std::string &string)
Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level,...
std::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.
void set_ostream_ptr(std::ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.