Example #1
0
int
Nestea_i::load_data (void)
{
  ACE_FILE_IO file;
  ACE_FILE_Connector connector;

  if (connector.connect (file,
                         ACE_FILE_Addr (this->data_filename_),
                         0,
                         ACE_Addr::sap_any) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n to %s",
                       "connect",
                       this->data_filename_),
                      -1);

  char str[MAX_UINT32_STR_LEN];

  int len = file.recv (str, MAX_UINT32_STR_LEN);
  str[len] = 0;

  if (len > 0)
    this->cans_ = ACE_OS::atoi (str);
  else
    this->cans_ = 0;
  return 0;
}
Example #2
0
int Logging_Server::make_log_file(ACE_FILE_IO& logging_file, ACE_SOCK_Stream* logging_peer)
{
    // sizeof operator could be used on string literal 
    // which will return the size including the NULL terminator 
    char filename[MAXHOSTNAMELEN + sizeof(".log")];

    if (0 != logging_peer)
    {
        // Use client host name as file name.
        ACE_INET_Addr logging_peer_addr;
        logging_peer->get_remote_addr(logging_peer_addr);
        logging_peer_addr.get_host_name(filename, MAXHOSTNAMELEN);
        strcat(filename, ".log");
    }
    else
    {
        strcpy(filename, "logging_server.log");
    }

    ACE_FILE_Connector connector;
    return connector.connect(logging_file,
            ACE_FILE_Addr(filename),
            0, // No time-out.
            ACE_Addr::sap_any, // Ignored.
            0, // Don't try to reuse the addr.
            O_RDWR | O_CREAT | O_APPEND,
            ACE_DEFAULT_FILE_PERMS);
}
Example #3
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[]){

  ACE_FILE_Info fileinfo;
  ACE_FILE_IO cli_file;
  ACE_FILE_Connector con;

  if(con.connect(cli_file,
		 ACE_FILE_Addr(argv[1]),
		 0,
		 ACE_Addr::sap_any,0,O_RDWR|O_APPEND|O_CREAT, ACE_DEFAULT_FILE_PERMS) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n to %s",
		      "connect","abc"), -1);

    ssize_t len =
      ACE_Utils::truncate_cast<ssize_t> (ACE_OS::strlen(argv[2] )+1);
    if(cli_file.send(argv[2],len)!= len){
      ACE_ERROR_RETURN((LM_ERROR,
			"%p\n","send"),1);
    }
    cli_file.close();
  }
  return 0;
}
Example #4
0
bool LameMP3::NewFile(const ACE_TString& filename, int samplerate, 
                      int channels, int bitrate)
{
    if(m_hMp3Stream)
        return false;

    //init MP3 encoder
    BE_CONFIG conf = {};
    conf.dwConfig = BE_CONFIG_LAME;

    conf.format.LHV1.dwStructVersion = CURRENT_STRUCT_VERSION;
    conf.format.LHV1.dwStructSize = CURRENT_STRUCT_SIZE;
    conf.format.LHV1.dwSampleRate = samplerate;
    conf.format.LHV1.dwReSampleRate = 0;
    conf.format.LHV1.nMode = channels == 1? BE_MP3_MODE_MONO : BE_MP3_MODE_STEREO;
    conf.format.LHV1.dwBitrate = bitrate;
    conf.format.LHV1.nPreset = 0; //LQP_NORMAL_QUALITY;
    conf.format.LHV1.nQuality = 0;
    conf.format.LHV1.bEnableVBR = 1;
    conf.format.LHV1.nVBRQuality = 4;
    conf.format.LHV1.bWriteVBRHeader = 1;
    conf.format.LHV1.bStrictIso = 0;

    DWORD dwBufferSize = 0;
    int err = initStream(&conf, &m_dwInSamples, &dwBufferSize, &m_hMp3Stream);
    if(err != 0)
        return false;

    m_dwChannels = channels;
    m_out_mp3data.resize(dwBufferSize);

    ACE_FILE_Connector con;
#if !defined(UNDER_CE)
    int ret = con.connect(m_outfile, ACE_FILE_Addr(filename.c_str()), 0, 
                          ACE_Addr::sap_any, 0, O_RDWR | O_CREAT | O_TRUNC);
#else
    int ret = con.connect(m_outfile, ACE_FILE_Addr(filename.c_str()),
        0, ACE_Addr::sap_any, 0, O_RDWR | O_CREAT, FILE_SHARE_READ | FILE_SHARE_WRITE);
#endif
    if(ret < 0)
    {
        closeStream(m_hMp3Stream);
        m_hMp3Stream = 0;
    }

    return ret >= 0;
}
Example #5
0
bool OggFile::Open(const ACE_TString& filename)
{
    ACE_FILE_Connector con;
    if(con.connect(m_out_file, ACE_FILE_Addr(filename.c_str()),
        0, ACE_Addr::sap_any, 0, O_RDWR | O_CREAT | O_TRUNC) < 0)
        return false;

    return true;
}
int Logging_Event_Handler::open () {

  static const char LOGFILE_SUFFIX[] = ".log";
  char filename[MAXHOSTNAMELEN + sizeof (LOGFILE_SUFFIX)];
  ACE_INET_Addr logging_peer_addr;

  logging_handler_.peer ().get_remote_addr (logging_peer_addr);
  logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN);
  ACE_OS::strcat (filename, LOGFILE_SUFFIX);

  ACE_FILE_Connector connector;
  connector.connect (log_file_,
                     ACE_FILE_Addr (filename),
                     0, // No timeout.
                     ACE_Addr::sap_any, // Ignored.
                     0, // Don't try to reuse the addr.
                     O_RDWR|O_CREAT|O_APPEND,
                     ACE_DEFAULT_FILE_PERMS);

  return reactor ()->register_handler 
    (this, ACE_Event_Handler::READ_MASK);
}
Example #7
0
int TPC_Logging_Handler::open (void *) {
  static const ACE_TCHAR LOGFILE_SUFFIX[] = ACE_TEXT (".log");
  ACE_TCHAR filename[MAXHOSTNAMELEN + sizeof (LOGFILE_SUFFIX)];
  ACE_INET_Addr logging_peer_addr;

  peer ().get_remote_addr (logging_peer_addr);
  logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN);
  ACE_OS::strcat (filename, LOGFILE_SUFFIX);

  ACE_FILE_Connector connector;
  connector.connect (log_file_,
                     ACE_FILE_Addr (filename),
                     0, // No timeout.
                     ACE_Addr::sap_any, // Ignored.
                     0, // Don't try to reuse the addr.
                     O_RDWR | O_CREAT | O_APPEND,
                     ACE_DEFAULT_FILE_PERMS);

  logging_handler_.peer ().set_handle (peer ().get_handle ());

  return activate (THR_NEW_LWP | THR_DETACHED);
}
Example #8
0
int
Nestea_i::save_data (void)
{
  ACE_FILE_IO file;
  ACE_FILE_Connector connector;

  if (connector.connect (file,
                         ACE_FILE_Addr (this->data_filename_),
                         0,
                         ACE_Addr::sap_any) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n to %s",
                       "connect",
                       this->data_filename_),
                      -1);

  char str[MAX_UINT32_STR_LEN];

  ACE_OS::sprintf (str, "%d", this->cans_);

  return file.send_n (str, ACE_OS::strlen (str) + 1);
}
Example #9
0
JAWS_Cached_FILE::JAWS_Cached_FILE (const char *const &filename,
                                    JAWS_Filecache_Proxy::Cache_Manager *cm)
  : JAWS_Filecache_Proxy (filename, cm)
{
  ACE_HANDLE handle = ACE_INVALID_HANDLE;

  if (this->data () != 0)
    {
      handle = ACE_OS::dup (this->data ()->get_handle ());
    }
  else
    {
      JAWS_FILE *file = new JAWS_FILE;
      ACE_FILE_Connector file_connector;

      int result = file_connector.connect (*file, ACE_FILE_Addr (filename));
      if (result == -1 || file->get_handle () == ACE_INVALID_HANDLE)
        {
          // TODO: do something here!
        }

      ACE_FILE_Info info;
      file->get_info (info);

      handle = ACE_OS::dup (file->get_handle ());

      {
        JAWS_Cached_FILE cf (filename, file, info.size_, cm);
        if (cf.data () != 0)
          {
            new (this) JAWS_Cached_FILE (filename, cm);
            return;
          }
      }
    }

  this->file_.set_handle (handle);
}
Example #10
0
int Logging_Server::make_log_file (ACE_FILE_IO &logging_file,
                                   ACE_SOCK_Stream *logging_peer)
{
  char filename[MAXHOSTNAMELEN + sizeof (".log")];

  if (logging_peer != 0) { // Use client's hostname as log file name.
    ACE_INET_Addr logging_peer_addr;
    logging_peer->get_remote_addr (logging_peer_addr);
    logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN);
    strcat (filename, ".log");
  }
  else
    strcpy (filename, "logging_server.log");

  ACE_FILE_Connector connector;
  return connector.connect (logging_file,
                            ACE_FILE_Addr (filename),
                            0, // No timeout.
                            ACE_Addr::sap_any, // Ignored.
                            0, // Don't try to reuse the addr.
                            O_RDWR|O_CREAT|O_APPEND,
                            ACE_DEFAULT_FILE_PERMS);
}
Example #11
0
 ACE_FILE_Addr get_outgoing_message (Message *)
 {
   // Exclude 23
   return ACE_FILE_Addr (ACE_TEXT ("/tmp/outgoing_message"));
   // Exclude 23
 }
Example #12
0
 ACE_FILE_Addr get_message_destination (Message *)
 {
   // Exclude 26
   return ACE_FILE_Addr (ACE_TEXT ("/tmp/encoded_message"));
   // Exclude 26
 }
Example #13
0
 ACE_FILE_Addr get_incoming_message_queue (void)
 {
   // Exclude 24
   return ACE_FILE_Addr (ACE_TEXT ("/tmp/incoming_message"));
   // Exclude 24
 }
static int
test_ostream (void)
{
  // This message should show up in the log file.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("first message\n")));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // This message should not show up anywhere.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("second message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
  // Create a persistent store.
  const ACE_TCHAR *filename = ACE_TEXT ("output");
  ofstream myostream (ACE_TEXT_ALWAYS_CHAR (filename), ios::out | ios::trunc);

  // Check for errors.
  if (myostream.bad ())
    return -1;

  // Set the ostream.
  ACE_LOG_MSG->msg_ostream (&myostream);

  // This message should show up in the ostream.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("fourth message\n")));
  // Set the ostream back to the test's log file.
  ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
  // Now close the ostream file and check its contents.
  myostream.close ();

  ACE_FILE_Connector connector;
  ACE_FILE_IO file;

  // Open up the file.
  if (connector.connect (file,
                         ACE_FILE_Addr (filename)) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("connect failed for %p\n"),
                         filename),
                        1);
    }

  // Unlink this file right away so that it is automatically removed
  // when the process exits.Ignore error returns in case this operation
  // is not supported.
  ACE_OS::unlink(filename);

  ACE_FILE_Info info;
  if (file.get_info (info) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("get_info failed on %p\n"),
                         filename),
                        -1);
    }

  // Allocate the input buffer
  char *buffer;
  ACE_NEW_RETURN (buffer,
                  char[info.size_ + 1],
                  -1);
  // Make sure <buffer> is released automagically.
  ACE_Auto_Basic_Array_Ptr<char> b (buffer);

  // Read the file into the buffer.
  ssize_t size = file.recv (buffer,
                            info.size_);
  if (size != info.size_)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Read %d bytes, rather than expected %d bytes\n"),
                         size,
                         info.size_),
                        -1);
    }
  // Make sure to NUL-terminate this turkey!
  buffer[size] = '\0';


  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%s"),
              buffer));

#endif /* ACE_LACKS_IOSTREAM_TOTALLY */

  // This message should show up in stderr and the ostream (without
  // ACE_LACKS_IOSTREAM_TOTALLY).
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("fifth message\n")));

  return 0;
}
Example #15
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc < 3 || argc > 3)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "usage: %s filename string\n",
                       argv[0]),
                      1);

  ACE_TCHAR *readback = new ACE_TCHAR[ACE_OS::strlen (argv[1]) + 1];

  ACE_FILE_Info fileinfo;
  ACE_FILE_IO cli_file;
  ACE_FILE_Connector con;

  if (con.connect (cli_file,
                   ACE_FILE_Addr (argv[1]),
		   0,
                   ACE_Addr::sap_any, 0,
		   O_RDWR|O_APPEND|O_CREAT,
                   ACE_DEFAULT_FILE_PERMS) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n to %s",
                       "connect",
                       argv[1]),
                      -1);

  ssize_t len = ACE_OS::strlen (argv[2]) + 1;

  if (cli_file.send (argv[2], len) != len)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      1);

  if (cli_file.get_info (&fileinfo) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "get_info"),
                      1);
  else
    ACE_OS::printf ("fileinfo : mode = %o\nno of links = %lu\nsize = %lu\n",
                    (u_int) fileinfo.mode_ & 0777,
                    static_cast<u_long > (fileinfo.nlink_),
                    (u_long) fileinfo.size_);

  ACE_OFF_T fpos = cli_file.tell ();

  if (fpos == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "tell"),
                      1);
  else
    ACE_OS::printf ("current filepointer is at %ld\n",
                    (long int) fpos);

  if (cli_file.seek (0,
                     SEEK_SET) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "seek"),
                      1);
  if (cli_file.recv (readback, len) != len)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "recv"),
                      1);

  ACE_OS::printf ("read back :%s\n",
                  readback);

  if (cli_file.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                      1);
  return 0;
}