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

http://github.com/tomahawk-player/tomahawk · C Header · 133 lines · 46 code · 27 blank · 60 comment · 0 complexity · 90f491b35f8173384265a686d347d12d 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 CLIENT_LINUX_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_
  30. #define CLIENT_LINUX_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_
  31. #include <pthread.h>
  32. #include <string>
  33. namespace google_breakpad {
  34. class ClientInfo;
  35. class CrashGenerationServer {
  36. public:
  37. // WARNING: callbacks may be invoked on a different thread
  38. // than that which creates the CrashGenerationServer. They must
  39. // be thread safe.
  40. typedef void (*OnClientDumpRequestCallback)(void* context,
  41. const ClientInfo* client_info,
  42. const std::string* file_path);
  43. typedef void (*OnClientExitingCallback)(void* context,
  44. const ClientInfo* client_info);
  45. // Create an instance with the given parameters.
  46. //
  47. // Parameter listen_fd: The server fd created by CreateReportChannel().
  48. // Parameter dump_callback: Callback for a client crash dump request.
  49. // Parameter dump_context: Context for client crash dump request callback.
  50. // Parameter exit_callback: Callback for client process exit.
  51. // Parameter exit_context: Context for client exit callback.
  52. // Parameter generate_dumps: Whether to automatically generate dumps.
  53. // Client code of this class might want to generate dumps explicitly
  54. // in the crash dump request callback. In that case, false can be
  55. // passed for this parameter.
  56. // Parameter dump_path: Path for generating dumps; required only if true is
  57. // passed for generateDumps parameter; NULL can be passed otherwise.
  58. CrashGenerationServer(const int listen_fd,
  59. OnClientDumpRequestCallback dump_callback,
  60. void* dump_context,
  61. OnClientExitingCallback exit_callback,
  62. void* exit_context,
  63. bool generate_dumps,
  64. const std::string* dump_path);
  65. ~CrashGenerationServer();
  66. // Perform initialization steps needed to start listening to clients.
  67. //
  68. // Return true if initialization is successful; false otherwise.
  69. bool Start();
  70. // Stop the server.
  71. void Stop();
  72. // Create a "channel" that can be used by clients to report crashes
  73. // to a CrashGenerationServer. |*server_fd| should be passed to
  74. // this class's constructor, and |*client_fd| should be passed to
  75. // the ExceptionHandler constructor in the client process.
  76. static bool CreateReportChannel(int* server_fd, int* client_fd);
  77. private:
  78. // Run the server's event loop
  79. void Run();
  80. // Invoked when an child process (client) event occurs
  81. // Returning true => "keep running", false => "exit loop"
  82. bool ClientEvent(short revents);
  83. // Invoked when the controlling thread (main) event occurs
  84. // Returning true => "keep running", false => "exit loop"
  85. bool ControlEvent(short revents);
  86. // Return a unique filename at which a minidump can be written
  87. bool MakeMinidumpFilename(std::string& outFilename);
  88. // Trampoline to |Run()|
  89. static void* ThreadMain(void* arg);
  90. int server_fd_;
  91. OnClientDumpRequestCallback dump_callback_;
  92. void* dump_context_;
  93. OnClientExitingCallback exit_callback_;
  94. void* exit_context_;
  95. bool generate_dumps_;
  96. std::string dump_dir_;
  97. bool started_;
  98. pthread_t thread_;
  99. int control_pipe_in_;
  100. int control_pipe_out_;
  101. // disable these
  102. CrashGenerationServer(const CrashGenerationServer&);
  103. CrashGenerationServer& operator=(const CrashGenerationServer&);
  104. };
  105. } // namespace google_breakpad
  106. #endif // CLIENT_LINUX_CRASH_GENERATION_CRASH_GENERATION_SERVER_H_