file_port_rep Class Reference

Inheritance diagram for file_port_rep:
posix_port_rep port_rep rep_struct

List of all members.

Public Member Functions

Public Attributes

Protected Attributes


Detailed Description

Definition at line 66 of file file_port.cpp.


Constructor & Destructor Documentation

file_port_rep ( int  kind,
FILE *  f2,
bool  cf2,
bool  lock2,
const string name2 
) [inline]

Definition at line 105 of file file_port.cpp.

References mmx::get_lock().

00106                                             :
00107       posix_port_rep (kind, fileno (f2)),
00108       f (f2), cf (cf2), lock (lock2), name (name2), next (-1) {
00109     if (lock) get_lock (f, this->kind); }
  inline ~file_port_rep () {

~file_port_rep (  )  [inline]

Definition at line 110 of file file_port.cpp.

References mmx::release_lock().

00110                            {
00111     if (lock) release_lock (f);
00112     if (cf) fclose (f); }


Member Function Documentation

port accept (  )  [virtual, inherited]

Reimplemented in socket_port_rep.

Definition at line 88 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00088                   {
00089   mmerr << "port= " << expression () << lf;
00090   ERROR ("socket server port expected");
00091 }

bool busy (  )  [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 80 of file file_port.cpp.

References file_port_rep::can_read(), and posix_port_rep::kind.

00080                {
00081     if (this->kind == 2) return can_read () > 0;
00082     return true;
00083   }

nat can_read (  )  [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 88 of file file_port.cpp.

References posix_port_rep::kind.

Referenced by file_port_rep::busy().

00088                   {
00089     if (next != -1) return 1;
00090     if (this->kind == 1 || feof (f) != 0) return 0;
00091     next= fgetc (f);
00092     if (next != -1) return 1;
00093     return 0;
00094   }

nat can_write (  )  [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 84 of file file_port.cpp.

References posix_port_rep::kind.

00084                    {
00085     if (this->kind == 2) return 0;
00086     return (nat) (-1);
00087   }

port component ( const string name  )  [virtual, inherited]

Reimplemented in composite_port_rep, and formatting_port_rep.

Definition at line 94 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00094                                        {
00095   mmerr << "port= " << expression () << lf;
00096   ERROR ("composite port expected");
00097 }

bool error_flag (  )  [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 39 of file port.cpp.

00039                       {
00040   return false;
00041 }

string error_message (  )  [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 44 of file port.cpp.

00044                          {
00045   return "";
00046 }

syntactic expression (  )  const [inline, virtual]

Implements port_rep.

Definition at line 74 of file file_port.cpp.

References posix_port_rep::kind, and mmx::syn().

00074                                 {
00075     if (this->kind == 1) return syn ("output_file_port", syntactic (name));
00076     if (this->kind == 2) return syn ("input_file_port", syntactic (name));
00077     return syn ("input_output_file_port", syntactic (name));
00078   }

void feed (  )  [virtual, inherited]

Reimplemented in socket_port_rep.

Definition at line 67 of file posix_port.cpp.

References posix_port_rep::alive, posix_port_rep::buffer, ERROR, posix_port_rep::fd, posix_port_rep::read(), and posix_port_rep::wait().

Referenced by posix_port_rep::busy(), posix_port_rep::can_read(), and posix_port_rep::read().

00067                       {
00068   while (alive && wait (0)) {
00069     int r;
00070     char tempout[1024];
00071     r = ::read (fd, tempout, 1024);
00072     if (r == -1) {
00073 #if defined(__MINGW__) || defined(__MINGW32__)
00074       _cwait (NULL, 0, _WAIT_CHILD);
00075 #else
00076       ::wait (NULL);
00077 #endif
00078       ERROR ("read failed");
00079     }
00080     else if (r == 0) alive= false;
00081     else buffer << string (tempout, r);
00082   }
00083 }

void flush (  )  [inline, virtual]

Reimplemented from port_rep.

Definition at line 102 of file file_port.cpp.

00102 { fflush (f); }

void format ( const print_format fm  )  [virtual, inherited]

Reimplemented in formatting_port_rep.

Definition at line 100 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00100                                         {
00101   mmerr << "port= " << expression () << lf;
00102   ERROR ("formatting port expected");  
00103 }

virtual bool is_input_port (  )  [inline, virtual, inherited]

Reimplemented from port_rep.

Definition at line 40 of file posix_port.hpp.

References posix_port_rep::kind.

00040 { return (kind & 2) != 0; }

virtual bool is_output_port (  )  [inline, virtual, inherited]

Reimplemented from port_rep.

Definition at line 39 of file posix_port.hpp.

References posix_port_rep::kind.

00039 { return (kind & 1) != 0; }

void read ( char *  s,
nat  n 
) [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 98 of file file_port.cpp.

00098                              {
00099     if (next != -1 && n > 0) { s[0]= next; s++; n--; next= -1; }
00100     for (nat i=0; i<n; i++) s[i]= fgetc (f); }

virtual void send ( const char *  s,
nat  n 
) [virtual, inherited]

Referenced by posix_port_rep::write().

bool wait ( int  msecs  )  [virtual, inherited]

Reimplemented from port_rep.

Definition at line 86 of file posix_port.cpp.

References posix_port_rep::alive, posix_port_rep::fd, and posix_port_rep::kind.

Referenced by socket_port_rep::accept(), socket_port_rep::feed(), and posix_port_rep::feed().

00086                                {
00087   //mmout << "Wait " << msecs << " ms on " << expression () << "\n";
00088   if ((kind & 2) == 0 || !alive) return false;
00089   fd_set in_fds;
00090   FD_ZERO (&in_fds);
00091   FD_SET (fd, &in_fds);
00092   
00093   nat nr;
00094   struct timeval tv;
00095   tv.tv_sec  = msecs / 1000;
00096   tv.tv_usec = 1000 * (msecs % 1000);
00097   if (msecs < 0) nr= select (fd + 1, &in_fds, NULL, NULL, NULL);
00098   else nr= select (fd + 1, &in_fds, NULL, NULL, &tv);
00099   //mmout << "Received " << nr << " on " << fd << "\n";
00100   return nr > 0;
00101 }

void write ( const char *  s,
nat  n 
) [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 96 of file file_port.cpp.

00096                                     {
00097     for (nat i=0; i<n; i++) fputc (s[i], f); }


Member Data Documentation

bool alive [protected, inherited]
string buffer [protected, inherited]
int fd [protected, inherited]
int kind [protected, inherited]
nat pos [protected, inherited]
MMX_ALLOCATORS int ref_count [inherited]

Definition at line 164 of file basix.hpp.


The documentation for this class was generated from the following file:

Generated on 6 Dec 2012 for basix by  doxygen 1.6.1