Skip to content

Commit

Permalink
use tango process and io redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfwood committed Oct 24, 2010
1 parent c9c101e commit 87ed26b
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions util/soundclip.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,85 @@ import tango.stdc.posix.unistd;
import tango.stdc.posix.signal;
import tango.stdc.stringz;
import tango.std.posix.stdlib;
tango.sys.Process;

class SoundClip{
private:
char[] exe;
char[] filename;
pid_t pid;
//pid_t pid;
bool paused;
Process p;


public:
this(char[] fn){
exe = "cvlc";
filename = fn;
pid = 0;
}

bool start(){
if(pid != 0){return false;}
if(p !is null){return false;}

if((pid = fork()) == 0){
char[] temp = exe ~ filename;

execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);
//if((pid = fork()) == 0){
char[] temp = exe ~ filename;

try{
p = new Process (temp, null);
p.copyEnv(true);

p.setRedirect(7);

p.execute;
}
catch (ProcessException e)
Stdout.formatln ("Process execution failed: {}", e);

}else{
//execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);

//}else{
// ???
if(pid > 0){
//if(pid > 0){

return true;
}else{
return false;
}
}
// return true;
//}else{
// return false;
//}
//}
}

bool stop(){
if(pid == 0){return false;}
if(p is null){return false;}

if(kill(pid, SIGKILL) != 0){return false;}
//if(kill(pid, SIGKILL) != 0){return false;}

//XXX: wait for child zombie

p.kill();

//auto result = p.wait;

//Stdout.formatln ("Process '{}' ({}) exited with reason {}, status {}",
// p.programName, p.pid, cast(int) result.reason, result.status);


return true;
}

bool pause(){
if(pid == 0 || paused){return false;}
if(p !is null || paused){return false;}

return signal(SIGSTOP);
}

bool unpause(){
if((pid == 0) || !paused){return false;}
if((p !is null) || !paused){return false;}

return signal(SIGCONT);
}


bool signal(int sig){
return (kill(pid, sig) == 0);
return (kill(p.pid, sig) == 0);
}
}

0 comments on commit 87ed26b

Please sign in to comment.