Re: Reading From A Pipe



int    pipefd2[2];    /* Read pipe from child */

Glib::RefPtr<Glib::IOChannel> readChannel;


//Instantiate
Playback playback;

// Connect the signal handler
Glib::signal_io().connect(sigc::mem_fun(playback, &Playback::readpipe), pipefd2[r], Glib::IO_IN);

// Create a writeChannel from the file descriptor
writeChannel = Glib::IOChannel::create_from_fd(pipefd1[w]);

// Create a readChannel from the file descriptor
readChannel = Glib::IOChannel::create_from_fd(pipefd2[r]);

app.run(playback);


// Read From Pipe
bool Playback::readpipe(Glib::IOCondition read_condition)
{
    static int linecount;    // Total lines expected
    static int count;    // Count of lines received



    if ((read_condition & Glib::IO_IN) == 0)
    {
        std::cerr << "Exxx: Invalid read response" << std::endl;
    }
    else
    {
        #ifdef GLIBMM_EXCEPTIONS_ENABLED
        readChannel->read_line(readbuffer);
        #else
        std::auto_ptr<Glib::Error> ex;
        readChannel->read_line(readbuffer, ex);
        if(ex.get())
            std::cerr << "Exxx: " << ex->what() << std::endl;
        #endif //GLIBMM_EXCEPTIONS_ENABLED

        /* Append message read from pipe to textbuffer */
        m_msg->insert(m_msg->end(), readbuffer);
    }
    return true;
} //End of readpipe()



On May 11, 2010, José Alburquerque <jaalburquerque cox net> wrote:



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