/thirdparty/breakpad/client/mac/crash_generation/crash_generation_server.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 141 lines · 53 code · 28 blank · 60 comment · 0 complexity · c1e47bc22e630eaa423b1c58ee206f17 MD5 · raw file

  1. // Copyright (c) 2010 Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #ifndef GOOGLE_BREAKPAD_CLIENT_MAC_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_
  30. #define GOOGLE_BREAKPAD_CLIENT_MAC_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_
  31. #include <stdint.h>
  32. #include <string>
  33. #include "common/mac/MachIPC.h"
  34. namespace google_breakpad {
  35. class ClientInfo;
  36. // Messages the server can read via its mach port
  37. enum {
  38. kDumpRequestMessage = 1,
  39. kAcknowledgementMessage = 2,
  40. kQuitMessage = 3
  41. };
  42. // Exception details sent by the client when requesting a dump.
  43. struct ExceptionInfo {
  44. int32_t exception_type;
  45. int32_t exception_code;
  46. int32_t exception_subcode;
  47. };
  48. class CrashGenerationServer {
  49. public:
  50. // WARNING: callbacks may be invoked on a different thread
  51. // than that which creates the CrashGenerationServer. They must
  52. // be thread safe.
  53. typedef void (*OnClientDumpRequestCallback)(void *context,
  54. const ClientInfo &client_info,
  55. const std::string &file_path);
  56. typedef void (*OnClientExitingCallback)(void *context,
  57. const ClientInfo &client_info);
  58. // Create an instance with the given parameters.
  59. //
  60. // mach_port_name: Named server port to listen on.
  61. // dump_callback: Callback for a client crash dump request.
  62. // dump_context: Context for client crash dump request callback.
  63. // exit_callback: Callback for client process exit.
  64. // exit_context: Context for client exit callback.
  65. // generate_dumps: Whether to automatically generate dumps.
  66. // Client code of this class might want to generate dumps explicitly
  67. // in the crash dump request callback. In that case, false can be
  68. // passed for this parameter.
  69. // dump_path: Path for generating dumps; required only if true is
  70. // passed for generateDumps parameter; NULL can be passed otherwise.
  71. CrashGenerationServer(const char *mach_port_name,
  72. OnClientDumpRequestCallback dump_callback,
  73. void *dump_context,
  74. OnClientExitingCallback exit_callback,
  75. void *exit_context,
  76. bool generate_dumps,
  77. const std::string &dump_path);
  78. ~CrashGenerationServer();
  79. // Perform initialization steps needed to start listening to clients.
  80. //
  81. // Return true if initialization is successful; false otherwise.
  82. bool Start();
  83. // Stop the server.
  84. bool Stop();
  85. private:
  86. // Return a unique filename at which a minidump can be written.
  87. bool MakeMinidumpFilename(std::string &outFilename);
  88. // Loop reading client messages and responding to them until
  89. // a quit message is received.
  90. static void *WaitForMessages(void *server);
  91. // Wait for a single client message and respond to it. Returns false
  92. // if a quit message was received or if an error occurred.
  93. bool WaitForOneMessage();
  94. OnClientDumpRequestCallback dump_callback_;
  95. void *dump_context_;
  96. OnClientExitingCallback exit_callback_;
  97. void *exit_context_;
  98. bool generate_dumps_;
  99. std::string dump_dir_;
  100. bool started_;
  101. // The mach port that receives requests to dump from child processes.
  102. ReceivePort receive_port_;
  103. // The name of the mach port. Stored so the Stop method can message
  104. // the background thread to shut it down.
  105. std::string mach_port_name_;
  106. // The thread that waits on the receive port.
  107. pthread_t server_thread_;
  108. // Disable copy constructor and operator=.
  109. CrashGenerationServer(const CrashGenerationServer&);
  110. CrashGenerationServer& operator=(const CrashGenerationServer&);
  111. };
  112. } // namespace google_breakpad
  113. #endif // GOOGLE_BREAKPAD_CLIENT_MAC_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_