RE: Whats the best way of doing this

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Title: Message
I thought something like:-
 
void write_picture(char *data) {
 FILE *fp;
 // data write here
}
 
int main(void)
{
 int n, fd[2],child_loop=-1;
 pid_t pid;
 char vidbuffer[MAXSIZE];
 if (pipe(fd) < 0) {
  err_sys("pipe error");
 }
 if ( (pid = fork()) < 0) {
  err_sys("fork error");
 } else  {
   while(-1) {
  if (pid > 0) {
   /* parent */
 
   // close the READ pipe as we dont use it as a parent
   close(fd[0]);
   
   // usual code here
   // start of loop
   
   // display function call here
   // write buffer[currentbufferid-1] to pipe
  
   // end of loop
   // write to the pipe and give it the DIEDIE command ;)
   write(fd[1], "DIEDIE", 6);
  
   return -1;
  } else { 
   /* child */
 
   // close the WRITE pipe as we dont use it as a child!
   close(fd[1]);
  
   while(child_loop) {
    // start of infinite loop 
    // read from pipe
    // it can either be a) frame data to write to disk or b) DIEDIE cmd
    // if diedie break out of loop and exit
    n=read(fd[0],vidbuffer,MAXSIZE);
    if(vidbuffer[0]=="D") && (vidbuffer[1]=="I") && (vidbuffer[2]=="E") && (vidbuffer[3]=="D") && (vidbuffer[4]=="I") && (vidbuffer[5]=="E") {
     // we got the die command, exit out of loop  
     child_loop=0;
    } else {
     // we just got piped a new frame to write to disk (yay!)
     write_picture(vidbuffer); 
    }
   }   
   // end of loop
   return -1;
  }
   }
 }
 
 exit(0);
}
 

Thanks,
Kind Regards,

Matt Brocklehurst,
LookCCTV.

Tel: 01253 891222
Fax: 01253 891221
Web: www.lookcctv.com
Email: matt@xxxxxxxxxxxx

 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003


[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux