Lolly 1.4.28
Loading...
Searching...
No Matches
spawn.hpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : spawn.hpp
4 * DESCRIPTION: external command handling
5 * COPYRIGHT : (C) 2015 Gregoire LECERF, Denis RAUX
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "array.hpp"
13
14#include <fcntl.h>
15#include <io.h>
16#include <process.h>
17#include <string>
18
19__stdcall unsigned bkgread (void*);
20
21class Channel {
22public:
23 friend unsigned int bkgread (void*);
24 enum Direction { CHOUT= 0, CHIN= 1 };
25 Channel (int s= 2048);
26 void Init (int fd, Direction d);
27 void Init (Direction d);
28 void redirect ();
29 inline int getPipe () const { return (toBeClosed); }
30 void read (std::string* str);
31 inline int write (void* data, int lenght) {
32 return (_write (fd, data, lenght));
33 }
34 void close ();
35 void closeUnused ();
36 void wait ();
37 ~Channel ();
38 const int sz;
39
40private:
42 return (t == CHOUT ? CHIN : CHOUT);
43 }
45 int origin;
46 int saved;
47 int fd;
48 std::string* str;
49 uintptr_t tid;
50 void restore ();
51};
52
54public:
55 spawn_system (array<Channel>& ch, char* name, const char* const* args);
56 inline int getpid () { return (pid); }
57 int wait ();
58 inline bool isRunning () { return (pid ? true : false); }
59
60private:
61 intptr_t pid;
63};
blackbox t[13]
const int sz
Definition spawn.hpp:38
void Init(int fd, Direction d)
Definition spawn.cpp:44
int fd
Definition spawn.hpp:47
std::string * str
Definition spawn.hpp:48
~Channel()
Definition spawn.cpp:100
int write(void *data, int lenght)
Definition spawn.hpp:31
Direction
Definition spawn.hpp:24
@ CHIN
Definition spawn.hpp:24
@ CHOUT
Definition spawn.hpp:24
void read(std::string *str)
Definition spawn.cpp:62
Channel(int s=2048)
Definition spawn.cpp:17
int getPipe() const
Definition spawn.hpp:29
void closeUnused()
Definition spawn.cpp:76
friend unsigned int bkgread(void *)
Definition spawn.cpp:110
int saved
Definition spawn.hpp:46
void close()
Definition spawn.cpp:68
int toBeClosed
Definition spawn.hpp:44
void restore()
Definition spawn.cpp:92
void redirect()
Definition spawn.cpp:55
int origin
Definition spawn.hpp:45
enum Direction otherDirection(Direction t)
Definition spawn.hpp:41
void wait()
Definition spawn.cpp:85
uintptr_t tid
Definition spawn.hpp:49
The list class represents a linked list.
Definition list.hpp:48
int wait()
Definition spawn.cpp:133
intptr_t pid
Definition spawn.hpp:61
array< Channel > & channel
Definition spawn.hpp:62
int getpid()
Definition spawn.hpp:56
spawn_system(array< Channel > &ch, char *name, const char *const *args)
Definition spawn.cpp:122
bool isRunning()
Definition spawn.hpp:58
__stdcall unsigned bkgread(void *)
Definition spawn.cpp:110