PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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