| 51 | } |
| 52 | |
| 53 | Firebird::ITracePlugin* TraceFactoryImpl::trace_create(Firebird::CheckStatusWrapper* status, |
| 54 | Firebird::ITraceInitInfo* initInfo) |
| 55 | { |
| 56 | Firebird::MasterInterfacePtr master; |
| 57 | const char* dbname = NULL; |
| 58 | try |
| 59 | { |
| 60 | dbname = initInfo->getDatabaseName(); |
| 61 | if (!dbname) |
| 62 | dbname = ""; |
| 63 | |
| 64 | TracePluginConfig config; |
| 65 | TraceCfgReader::readTraceConfiguration(initInfo->getConfigText(), dbname, config); |
| 66 | |
| 67 | Firebird::ITraceDatabaseConnection* connection = initInfo->getConnection(); |
| 68 | |
| 69 | if (!config.enabled || |
| 70 | (config.connection_id && connection && |
| 71 | (connection->getConnectionID() != config.connection_id))) |
| 72 | { |
| 73 | return NULL; // Plugin is not needed, no error happened. |
| 74 | } |
| 75 | |
| 76 | Firebird::AutoPtr<Firebird::ITraceLogWriter, Firebird::SimpleRelease> |
| 77 | logWriter(initInfo->getLogWriter()); |
| 78 | |
| 79 | if (logWriter) |
| 80 | config.log_filename = ""; |
| 81 | |
| 82 | return FB_NEW TracePluginImpl(this, config, initInfo); // Everything is ok, we created a plugin |
| 83 | |
| 84 | } |
| 85 | catch (Firebird::Exception& ex) |
| 86 | { |
| 87 | // put error into trace log |
| 88 | Firebird::ITraceLogWriter* logWriter = initInfo->getLogWriter(); |
| 89 | if (logWriter) |
| 90 | { |
| 91 | const char* strEx = TracePluginImpl::marshal_exception(ex); |
| 92 | Firebird::string err; |
| 93 | if (dbname && dbname[0]) |
| 94 | err.printf("Error creating trace session for database \"%s\":\n%s\n", dbname, strEx); |
| 95 | else |
| 96 | err.printf("Error creating trace session for service manager attachment:\n%s\n", strEx); |
| 97 | |
| 98 | logWriter->write(err.c_str(), err.length()); |
| 99 | logWriter->release(); |
| 100 | } |
| 101 | else |
| 102 | ex.stuffException(status); |
| 103 | } |
| 104 | |
| 105 | return NULL; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | static Firebird::SimpleFactory<TraceFactoryImpl> traceFactory; |
no test coverage detected