MSVC project changes needed to support the new 'mp3 import' stuff
[ardour.git] / libs / pbd / transmitter.cc
1 /*
2  * Copyright (C) 1998-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <cstdlib>
21 #include <signal.h>
22 #include <string>
23
24 #include "pbd/transmitter.h"
25 #include "pbd/error.h"
26
27 using std::string;
28 using std::ios;
29
30 Transmitter::Transmitter (Channel c)
31 {
32         channel = c;
33         switch (c) {
34         case Error:
35                 send = &error;
36                 break;
37         case Warning:
38                 send = &warning;
39                 break;
40         case Info:
41                 send = &info;
42                 break;
43         case Fatal:
44                 send = &fatal;
45                 break;
46         case Throw:
47                 /* we should never call Transmitter::deliver
48                    for thrown messages (because its overridden in the
49                    class heirarchy). force a segv if we do.
50                 */
51                 send = 0;
52                 break;
53         }
54 }
55
56 void
57 Transmitter::deliver ()
58
59 {
60         /* NOTE: this is just a default action for a Transmitter or a
61            derived class. Any class can override this to produce some
62            other action when deliver() is called.
63         */
64
65         *this << '\0';
66
67         /* send the SigC++ signal */
68
69         (*send) (channel, str().c_str());
70
71         /* XXX when or how can we delete this ? */
72         // delete foo;
73
74         /* return to a pristine state */
75
76         clear ();
77         seekp (0, ios::beg);
78         seekg (0, ios::beg);
79
80         /* do the right thing if this should not return */
81
82         if (does_not_return()) {
83 #ifndef PLATFORM_WINDOWS
84 // TODO !!!! Commented out temporarily (for Windows)
85                 sigset_t mask;
86
87                 sigemptyset (&mask);
88                 sigsuspend (&mask);
89                 /*NOTREACHED*/
90                 exit (EXIT_FAILURE);
91 /* JE - From what I can tell, the above code suspends
92  * program execution until (any) signal occurs. Not
93  * sure at the moment what this achieves, unless it
94  * provides some time for the user to see the message.
95  */
96 #endif
97         }
98 }
99
100 bool
101 Transmitter::does_not_return ()
102
103 {
104         if (channel == Fatal || channel == Throw) {
105                 return true;
106         } else {
107                 return false;
108         }
109 }
110
111
112 extern "C" {
113   void pbd_c_error (const char *str)
114
115   {
116         PBD::error << str << endmsg;
117   }
118 }