/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 214 by schoenebeck, Sat Aug 14 23:00:44 2004 UTC revision 319 by schoenebeck, Mon Dec 13 00:46:42 2004 UTC
# Line 27  Line 27 
27  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
28  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
29  #include "network/lscpserver.h"  #include "network/lscpserver.h"
30    #include "common/stacktrace.h"
31    #include "common/Features.h"
32    
33  using namespace LinuxSampler;  using namespace LinuxSampler;
34    
35  Sampler*    pSampler    = NULL;  Sampler*    pSampler    = NULL;
36  LSCPServer* pLSCPServer = NULL;  LSCPServer* pLSCPServer = NULL;
37  pthread_t   signalhandlerthread;  pthread_t   main_thread;
38    
39  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
40  void signal_handler(int signal);  void signal_handler(int signal);
41    void kill_app();
42    
43  int main(int argc, char **argv) {  int main(int argc, char **argv) {
44    
45        // initialize the stack trace mechanism with our binary file
46        StackTraceInit(argv[0], -1);
47    
48        main_thread = pthread_self();
49    
50      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
     signalhandlerthread = pthread_self();  
51      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
52    
53        // register signal handler for all unusual signals
54        // (we will print the stack trace and exit)
55        struct sigaction sact;
56        sigemptyset(&sact.sa_mask);
57        sact.sa_flags   = 0;
58        sact.sa_handler = signal_handler;
59        sigaction(SIGSEGV, &sact, NULL);
60        sigaction(SIGBUS,  &sact, NULL);
61        sigaction(SIGILL,  &sact, NULL);
62        sigaction(SIGFPE,  &sact, NULL);
63        sigaction(SIGUSR1, &sact, NULL);
64        sigaction(SIGUSR2, &sact, NULL);
65    
66      // parse and assign command line options      // parse and assign command line options
67      //parse_options(argc, argv);      //parse_options(argc, argv);
68    
69      dmsg(1,("LinuxSampler %s\n", VERSION));      dmsg(1,("LinuxSampler %s\n", VERSION));
70      dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));      dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
71    
72        // detect and print system / CPU specific features
73        String sFeatures;
74        Features::detect();
75        #if ARCH_X86
76        if (Features::supportsMMX()) sFeatures += " MMX";
77        if (Features::supportsSSE()) sFeatures += " SSE";
78        #endif // ARCH_X86
79        if (!sFeatures.size()) sFeatures = " None";
80        dmsg(1,("Detected features:%s\n",sFeatures.c_str()));
81    
82      // create LinuxSampler instance      // create LinuxSampler instance
83      dmsg(1,("Creating Sampler..."));      dmsg(1,("Creating Sampler..."));
84      pSampler = new Sampler;      pSampler = new Sampler;
# Line 77  int main(int argc, char **argv) { Line 107  int main(int argc, char **argv) {
107      return EXIT_SUCCESS;      return EXIT_SUCCESS;
108  }  }
109    
110  void signal_handler(int signal) {  void signal_handler(int iSignal) {
111      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      switch (iSignal) {
112          if (pLSCPServer) {          case SIGINT: {
113              pLSCPServer->StopThread();              if (pthread_equal(pthread_self(), main_thread)) {
114              delete pLSCPServer;                  if (pLSCPServer) {
115                        pLSCPServer->StopThread();
116                        delete pLSCPServer;
117                    }
118                    if (pSampler) delete pSampler;
119                    printf("LinuxSampler stopped due to SIGINT.\n");
120                    exit(EXIT_SUCCESS);
121                }
122                return;
123            }
124            case SIGSEGV:
125                std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush;
126                break;
127            case SIGBUS:
128                std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush;
129                break;
130            case SIGILL:
131                std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush;
132                break;
133            case SIGFPE:
134                std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush;
135                break;
136            case SIGUSR1:
137                std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush;
138                break;
139            case SIGUSR2:
140                std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush;
141                break;
142            default: { // this should never happen, as we register for the signals we want
143                std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush;
144                break;
145          }          }
         if (pSampler) delete pSampler;  
         printf("LinuxSampler stopped due to SIGINT\n");  
         exit(EXIT_SUCCESS);  
146      }      }
147        signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
148        std::cerr << "Showing stack trace...\n" << std::flush;
149        StackTrace();
150        sleep(2);
151        std::cerr << "Killing LinuxSampler...\n" << std::flush;
152        kill_app(); // Use abort() if we want to generate a core dump.
153    }
154    
155    void kill_app() {
156        kill(main_thread, SIGKILL);
157  }  }
158    
159  /*void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {

Legend:
Removed from v.214  
changed lines
  Added in v.319

  ViewVC Help
Powered by ViewVC