forked_player.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 
00024 #ifdef XWIN
00025 
00026 
00027 #ifndef ALPHA_LINUX_CXX
00028 #  include <csignal>
00029 #endif
00030 #include <unistd.h>
00031 
00032 #include "Configuration.h"
00033 #include "exult.h"
00034 #include "fnames.h"
00035 #include "forked_player.h"
00036 #include <iostream>
00037 
00038 using std::cerr;
00039 using std::endl;
00040 
00041 // NB: This function doesn't return unless execlp fails!
00042 static  void    playFJmidifile(const char *name)
00043 {
00044   execlp("playmidi","-v","-v","-e",name,0);
00045 }
00046 
00047 forked_player::forked_player() : forked_job(-1)
00048 {}
00049 
00050 void  forked_player::stop_track(void)
00051 {
00052   if(forked_job!=-1)
00053     kill(forked_job,SIGKILL);
00054   forked_job=-1;
00055 }
00056 
00057 forked_player::~forked_player(void)
00058 {
00059   stop_track();
00060 }
00061 
00062 bool  forked_player::is_playing(void)
00063 {
00064   if(forked_job==-1)
00065     return false;
00066   if(kill(forked_job,0))
00067     {
00068     forked_job=-1;
00069     return false;
00070     }
00071   return true;
00072 }
00073 
00074 
00075 void  forked_player::start_track(XMIDIEventList *event_list,bool repeat)
00076 {
00077   static char *name = 0;
00078 
00079   if (name == 0) {
00080     name = new char[19];
00081     strcpy(name, "/tmp/u7midi_XXXXXX");
00082     close(mkstemp(name));
00083     // TODO: delete this file on exit
00084   }
00085 
00086   event_list->Write(name);
00087 
00088   repeat_=repeat;
00089 #if DEBUG
00090   cerr << "Starting midi sequence with forked_player" << endl;
00091 #endif
00092   if(forked_job!=-1)
00093   {
00094 #if DEBUG
00095     cerr << "Stopping any running track" << endl;
00096 #endif
00097     stop_track();
00098   }
00099 
00100   forked_job=fork();
00101   if(!forked_job)
00102   {
00103     playFJmidifile(name); // this doesn't return if it started correctly
00104     cerr << "Starting forked player failed" << endl;
00105     exit(-1);
00106   }
00107 }
00108 
00109 const char *forked_player::copyright(void)
00110 {
00111   return "Internal cheapass forked midi player";
00112 }
00113 
00114 #endif // XWIN

Generated on Mon Jul 9 14:42:41 2007 for ExultEngine by  doxygen 1.5.1