Exemplo n.º 1
0
 void
 info_out_data_listener_exec_i::on_one_data (
   const ::DDSHello & datum,
   const ::CCM_DDS::ReadInfo & /* info */)
 {
   ++this->received_;
   ACE_CString rec (datum.hello.in ());
   ACE_Date_Time now;
   int const sec_rec = ACE_OS::atoi (rec.substr (0, 2).c_str() );
   if (sec_rec > 0)
     {
       int usec_rec = ACE_OS::atoi (rec.substr (3, 6).c_str ());
       if (sec_rec != now.second ())
         {
           usec_rec += 10000000;
         }
       ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("<%C> received <%C> - <%d>. difference <%d>\n"),
                   this->name_.c_str (),
                   datum.hello.in (),
                   datum.iterator,
                   now.microsec () - usec_rec));
     }
   else
   {
     ACE_DEBUG ((LM_DEBUG, ACE_TEXT("<%C> received <%C> - <%d>.\n"),
     this->name_.c_str (),
     datum.hello.in (),
     datum.iterator));
   }
 }
Exemplo n.º 2
0
Identifier::Identifier (const char *s)
  : pv_string (0),
    escaped_ (false)
{
  bool shift = false;

  if (*s == '_')
    {
      // Only one leading underscore is allowed.
      if (s[1] == '_')
        {
          idl_global->err ()->error0 (UTL_Error::EIDL_UNDERSCORE);
        }

      shift = true;
      this->escaped_ = true;
      ACE_CString str (s);
      const char *c_prefix = "_cxx_";

      if (str.find ("_tc_") == 0
          || str.find ("_tao_") == 0)
        {
          shift = false;
        }
      else if (str.find (c_prefix) == 0)
        {
          str = str.substr (ACE_OS::strlen (c_prefix));
          const char *eh_suffix = "_excep";
          ACE_CString::size_type pos =
            str.length () - ACE_OS::strlen (eh_suffix);

          // If we have an AMI exception holder suffix, strip it off.
          if (str.find (eh_suffix) == pos)
            {
              str = str.substr (0, pos);
            }

          TAO_IDL_CPP_Keyword_Table cpp_key_tbl;
          unsigned int len =
            static_cast<unsigned int> (str.length ());
          const TAO_IDL_CPP_Keyword_Entry *entry =
            cpp_key_tbl.lookup (str.c_str (), len);

          if (entry != 0)
            {
              shift = false;
            }
        }
    }

  if (shift)
    {
      this->pv_string = ACE::strnew (s + 1);
    }
  else
    {
      this->pv_string = ACE::strnew (s);
    }
}
Exemplo n.º 3
0
bool BACIValue::fromString(const ACE_CString value, bool specifyType)
{

  ACE_CString strType;
  ACE_CString strContent;
  const char *szType;
  const char *szContent;
  unsigned long ulBound = 0;

  if (specifyType)
    {
      ACE_CString::size_type nPos0 = value.find('<');
      ACE_CString::size_type nPos1 = value.find(':');
      ACE_CString::size_type nPos2 = value.find('>');

      if((nPos1 != ACE_CString::npos) && (nPos1 < (nPos2-1)))
		ulBound = atoi(value.substr(nPos1+1, nPos2-nPos1-1).c_str());
      else
		nPos1 = nPos2;

      strType = value.substr(nPos0+1, nPos1-nPos0-1);
      strContent = value.substr(nPos2+1);
      szType = strType.c_str();
      szContent = strContent.c_str();

    }
  else
    {
      strType = typeName[type_m];
      strContent = value;
      szType = strType.c_str();
      szContent = strContent.c_str();
    }

/// User defined

  // special threathment for string (no conversion needed)
  if(strType.compare(BACIValue::typeName[type_string]) == 0)
    {
      if ((ulBound != 0) && (strContent.length() > ulBound))
	return false;
      if(!setType(type_string, ulBound))
	return 0;
      return stringValue(szContent);
    }

   PROCESS_INLINE_TYPE(double, BACIdouble)
   PROCESS_INLINE_TYPE(float, BACIfloat)
   PROCESS_INLINE_TYPE(long, BACIlong)
   PROCESS_INLINE_TYPE(longLong, BACIlongLong)
   PROCESS_INLINE_TYPE(uLongLong, BACIuLongLong)
//TBDeleted   PROCESS_INLINE_TYPE(pattern, BACIpattern)

  return false;

}
Exemplo n.º 4
0
    bool GetCmdLine(const ACE_CString& input, ACE_CString& cmd, ACE_CString& remain_input)
    {
        if(input.find('\n') != ACE_TString::npos)
        {
            size_t pos = input.find('\n');
            cmd = input.substr(0, pos+1);
            size_t len = input.length();
            remain_input = input.substr(pos+1, len-pos+1);

            return true;
        }
        return false;
    }
Exemplo n.º 5
0
UTL_ScopedName *
FE_Utils::string_to_scoped_name (const char *s)
{
  UTL_ScopedName *retval = 0;
  ACE_CString str (s);
  Identifier *id = 0;
  UTL_ScopedName *sn = 0;

  while (! str.empty ())
    {
      // Skip a leading double colon.
      if (str.find (':') == 0)
        {
          str = str.substr (2);
        }

      // Find the next double colon (if any) and get the next
      // name segment.
      ACE_CString::size_type pos = str.find (':');
      ACE_CString lname (str.substr (0, pos));

      // Construct a UTL_ScopedName segment.
      ACE_NEW_RETURN (id,
                      Identifier (lname.c_str ()),
                      0);

      ACE_NEW_RETURN (sn,
                      UTL_ScopedName (id, 0),
                      0);

      // Either make it the head of a new list or the tail of
      // an existing one.
      if (retval == 0)
        {
          retval = sn;
        }
      else
        {
          retval->nconc (sn);
        }

      // Update the working string.
      str = str.substr (pos);
    }

  return retval;
}
Exemplo n.º 6
0
    bool GetCmd(const ACE_CString& input, ACE_CString& cmd)
    {
        size_t nEndCommand = 0;
        while(nEndCommand < input.length() && 
            input[nEndCommand] != ' ' 
            && input[nEndCommand] != '\r' && 
            input[nEndCommand] != '\n')nEndCommand++;

        if(nEndCommand)
            cmd = input.substr(0,nEndCommand);
        return nEndCommand>0;
    }
Exemplo n.º 7
0
bool
FE_Utils::is_include_file_found (ACE_CString & inc_file,
                                 UTL_String * idl_file_name)
{
  char abspath[MAXPATHLEN] = "";
  char *full_path = 0;

  // If the include path has literal "s (because of an include
  // of a Windows path with spaces), we must remove them here.
  const char *tmp_inc_file = inc_file.c_str ();

  if (tmp_inc_file
      && FE_Utils::hasspace (tmp_inc_file)
      && tmp_inc_file[0] == '\"')
    {
      inc_file =
        inc_file.substr (1, inc_file.length () - 2);
    }

  inc_file += ACE_DIRECTORY_SEPARATOR_STR_A;
  inc_file += idl_file_name->get_string ();
  full_path =
    ACE_OS::realpath (inc_file.c_str (), abspath);

  if (full_path != 0)
    {
      FILE *test = ACE_OS::fopen (abspath, "r");

      if (test == 0)
        {
          return false;
        }
      else
        {
          // Overwrite inc_file with abspath since the later
          // is normalized to the native OS representation.
          inc_file = abspath;
          ACE_OS::fclose (test);
          return true;
        }
    }

  return false;
}
Exemplo n.º 8
0
ACE_TCHAR *
ACE::HTBP::ID_Requestor::get_HTID ()
{
  if (ACE::HTBP::ID_Requestor::htid_.length() != 0)
    return ACE::HTBP::ID_Requestor::htid_.rep();

  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, ACE::HTBP::ID_Requestor::htid_lock_, 0);

  if (ACE::HTBP::ID_Requestor::htid_.length() != 0)
    return ACE::HTBP::ID_Requestor::htid_.rep();

  ACE_SOCK_Stream cli_stream;
  ACE_TCHAR * htid = 0;

  if (this->url_.length() == 0 ||
      this->connect_to_server (&cli_stream) == -1 ||
      this->send_request (&cli_stream) == -1)
    {
      ACE_Utils::UUID_Generator gen;
      ACE_Utils::UUID *uuid = gen.generate_UUID ();
      const ACE_CString *uuidstr = uuid->to_string();
      ACE::HTBP::ID_Requestor::htid_ = ACE_TEXT_CHAR_TO_TCHAR (uuidstr->c_str());
      delete uuid;
      return ACE::HTBP::ID_Requestor::htid_.rep();
    }
  iovec recv_buf;
  ssize_t result = cli_stream.recvv (&recv_buf);
  cli_stream.close();

  if (result > 0)
    {
      ACE_CString answer ((char *)recv_buf.iov_base,recv_buf.iov_len);
      ACE_CString::size_type start = answer.rfind (ACE_TEXT('\n'));
      if (start == ACE_CString::npos)
        start = 0;
      else
        start++;
      ACE::HTBP::ID_Requestor::htid_ = ACE_TEXT_CHAR_TO_TCHAR(answer.substr (start).c_str());
      htid = ACE::HTBP::ID_Requestor::htid_.rep();
    }
  return htid;
}
Exemplo n.º 9
0
void
Library::set_path (const char *p)
{
  char abspath[1000];
  ACE_OS::memset (abspath,0,1000);
  ssize_t abspathlen = ACE_OS::readlink(p,abspath,999);
  ACE_CString path (p);
  if (abspathlen > 0) {
    abspath[abspathlen] = 0;
    path = abspath;
  }

  ACE_CString::size_type pathsep = path.rfind('/');

  if (pathsep == ACE_CString::npos) {
    path_ = ".";
  } else {
    path_ = path.substr(0,pathsep);
  }
}
Exemplo n.º 10
0
int
BE_GlobalData::outfile_init (TAO_OutStream *& os,
                             const char *file_prefix,
                             const char *file_suffix,
                             const char *guard_prefix,
                             const char *guard_suffix)
{
  ACE_NEW_RETURN (os,
                  TAO_SunSoft_OutStream,
                  -1);

  ACE_CString fn (idl_global->stripped_filename ()->get_string ());
  fn = fn.substr (0, fn.rfind ('.'));
  fn += file_suffix;

  const char *path = be_global->output_dir ();
  ACE_CString target_name;

  if (path != 0)
    {
      target_name = path;
      target_name += "/";
    }

  target_name += file_prefix;
  target_name += fn;

  if (os->open (target_name.c_str ()) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Failed to open file %s for writing.\n",
                         target_name.c_str ()),
                        -1);
    }

  *os << be_nl;

  os->gen_ifndef_string (fn.c_str (), guard_prefix, guard_suffix);

  return 0;
}
Exemplo n.º 11
0
UTL_ScopedName *
ast_visitor_reifying::template_module_rel_name (AST_Decl *d)
{
  AST_Decl *tmp = d;
  ACE_CString name (d->full_name ());

  while (tmp != 0)
    {
      if (AST_Template_Module::narrow_from_decl (tmp) != 0)
        {
          ACE_CString head (tmp->local_name ()->get_string ());

          ACE_CString::size_type start = name.find (head) + 2;

          ACE_CString tail (name.substr (start + head.length ()));

          return FE_Utils::string_to_scoped_name (tail.c_str ());
        }

      tmp = ScopeAsDecl (tmp->defined_in ());
    }

  return 0;
}
Exemplo n.º 12
0
UTL_ScopedName *
be_visitor_xplicit_pre_proc::xplicit_iface_rel_name (AST_Decl *d)
{
  AST_Decl *tmp = d;
  ACE_CString name (d->full_name ());

  while (tmp != 0)
    {
      if (be_home::narrow_from_decl (tmp) != 0)
        {
          ACE_CString head (tmp->local_name ()->get_string ());

          ACE_CString::size_type start = name.find (head) + 2;

          ACE_CString tail (name.substr (start + head.length ()));

          return FE_Utils::string_to_scoped_name (tail.c_str ());
        }

      tmp = ScopeAsDecl (tmp->defined_in ());
    }

  return 0;
}
Exemplo n.º 13
0
static ACE_THR_FUNC_RETURN
process(void* arg){
  ACE_INET_Addr addr;
  ACE_SOCK_Stream stream;
  ACE_HANDLE handle = (ACE_HANDLE) (intptr_t) arg;
  stream.set_handle(handle);
  /*make sure we're not in non-blocking mode.*/
  if(stream.disable(ACE_NONBLOCK) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "disable"),
		      0);
  }
  else if(stream.get_remote_addr(addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "get_remote_addr"),
		      0);
  }
  ACE_DEBUG ((LM_INFO,
	      "(%P|%t:%l) client %s connected from %d\n",
	      addr.get_host_name (),
	      addr.get_port_number ()));
  
  int r_bytes = 0;
  char buf[SIZE];
  ACE_CString cs;
  do{
    r_bytes = stream.recv(buf, SIZE);

    if(r_bytes == 0 || r_bytes == -1){
      ACE_DEBUG((LM_INFO,
		 "(%P|%t:%l) r_bytes = %d, exit from the loop\n", r_bytes));
      break;
    }
    for(int i=0; i< r_bytes; i++){
      cs += buf[i];
    }
  }while(true);
  stream.close_reader();
  /*
  ACE_DEBUG((LM_INFO,
	     "%s\n", cs.c_str()));
  */
  /*the layout of the message would be:
   * ^^pq||step1$$
   * 1st step: get the d by pq
   * 2nd calculate
   * 3rd send back the digest
   */
  int p0, p1;
  int len = cs.length();
  p0 = 2;
  p1 = cs.find("||");
  ACE_CString pq = cs.substr(2, p1 - 2);
  ACE_CString step1 = cs.substr(p1 + 2, len - p1 -4);
  /*
  ACE_DEBUG((LM_INFO,
	     "pq = %s\n step1 = %s\n", pq.c_str(), step1.c_str()));
  */
  //get the d
  ACE_CString sql = "select d,textid from player0 where pq='";
  sql += pq;
  sql += "'";
  /*
  ACE_DEBUG((LM_INFO,
	     "sql = %s\n", sql.c_str()));
*/
  PGconn* con;
  con = PQconnectdb("host=45.33.3.188 port=5432 dbname=nv user=dec");
  PGresult* res;
  if(PQstatus(con)!= CONNECTION_OK){
    ACE_DEBUG((LM_INFO,
	       "Connection to database failed:%s\n",
	       PQerrorMessage(con)));
    reclaim_conn(con);
  }
  res = PQexec(con, sql.c_str());
  int n = PQntuples(res);
  if(n != 1){
    ACE_ERROR((LM_ERROR,
	       "there is significant error: %d\n", n));
    //    return 0;
  }
  ACE_CString d = "";
  d += PQgetvalue(res, 0, 0);
  /*
  ACE_DEBUG((LM_INFO,
	     "d = %s\n", d.c_str()));
*/
  bn* pq_ = from_hex(&pq);
  bn* d_ = from_hex(&d);
  bn* step1_ = from_hex(&step1);
  bn* step2_ = npmod(step1_ , d_ , pq_ );
  ACE_CString* step2 = step2_->to_hex();
  
  //check if the pq is taking the ownnership?

  /* if pq is 'centralbank', bypass the check, otherwise check the payer whether has the ownnership of the note;
   * select count(*) from ownership0 o, player0 p where o.owner = p.textid  and o.note='0x12345678' and p.pq='0x12345678';
   */
  bn* e_ = new bn(1);
  e_->addat(0,0x10001);
  bn* step3_ = npmod(step2_ , e_ , pq_ );
  ACE_CString* rawMsg = encode(step3_);
  ACE_DEBUG((LM_INFO,
	     "%T :%l step3 = %s\n", rawMsg->c_str()));
  if(verify_ownership(rawMsg, pq)){
    //update the ownership;
    int pos1 = rawMsg->find("->");
    ACE_CString note = rawMsg->substr(2, pos1 -2);
    int rawlen = rawMsg->length();
    ACE_CString id = rawMsg->substr(pos1 + 2, rawlen - pos1 - 6);
    update_ownership(note, id);
    /*insert the log entry*/
    insert_logentry(pq, *step2, *rawMsg, note, id);
    stream.send( step2->c_str(), step2->length());
    /*
    ACE_DEBUG((LM_INFO,
	       "%T :%l the step2 message is:\n%s\n", step2->c_str()));
    */
  }else{
    ACE_DEBUG((LM_INFO,
	       "%T :%l invalid transfer\n"));
    ACE_CString reply ="invalid transfer\n";
    stream.send( reply.c_str(), reply.length());
  }
  delete step2 ;
  delete pq_;
  delete d_;
  delete step1_;
  delete step2_;
  delete e_;
  delete step3_;
  delete rawMsg;
  /*
  stream.close_writer();
  */
  stream.close();
  ACE_DEBUG((LM_INFO,
	     "%T :%l closed the stream\n"));

}
Exemplo n.º 14
0
CORBA::ULong
TAO_SCIOP_Endpoint::preferred_interfaces (TAO_ORB_Core *oc)
{
  ACE_CString tmp (
    oc->orb_params ()->preferred_interfaces ());

  ACE_CString::size_type pos = 0;

  pos = tmp.find (this->host_.in ());

  TAO_SCIOP_Endpoint *latest = this;

  CORBA::ULong count = 0;

  while (pos != ACE_CString::npos)
    {
      // Do we have a "," or an '\0'?
      ACE_CString::size_type new_pos = tmp.find (",", pos + 1);

      // Length of the preferred path
      ACE_CString::size_type length = 0;

      if (new_pos == ACE_CString::npos)
        length = tmp.length () - pos;
      else
        length = new_pos - pos;

      ACE_CString rem_tmp = tmp.substr (pos, length);

      // Search for the ":"
      ACE_CString::size_type col_pos = rem_tmp.find (":");

      if (col_pos == ACE_CString::npos)
        {
          pos = tmp.find (latest->host_.in (),
                          pos + length);
          continue;
        }

      ACE_CString path = rem_tmp.substr (col_pos + 1);

      latest->preferred_path_.host =
        CORBA::string_dup (path.c_str ());

      if (TAO_debug_level > 3)
        TAOLIB_DEBUG ((LM_DEBUG,
                    "(%P|%t) Adding path [%C] "
                    " as preferred path for [%C]\n",
                    path.c_str (), this->host_.in ()));

      pos = tmp.find (latest->host_.in (),
                      pos + length);

      if (pos != ACE_CString::npos)
        {
          TAO_Endpoint *tmp_ep =
            latest->duplicate ();

          latest->next_ = dynamic_cast<TAO_SCIOP_Endpoint *> (tmp_ep);

          if (latest->next_ == 0) return count;

          latest = latest->next_;
          ++count;
        }
    }

  if (tmp.length () != 0 &&
      !oc->orb_params ()->enforce_pref_interfaces ())
    {
      TAO_Endpoint *tmp_ep = latest->duplicate ();

      latest->next_ =
        dynamic_cast<TAO_SCIOP_Endpoint *> (tmp_ep);

      if (latest->next_ == 0) return count;

      latest->next_->preferred_path_.host = (const char *) 0;
      ++count;
    }

  return count;
}
Exemplo n.º 15
0
int
be_visitor_ami_pre_proc::visit_interface (be_interface *node)
{
  // We check for an imported node after generating the reply handler.
  if (node->is_local () || node->is_abstract ())
    {
      return 0;
    }

  // The following 3 IF blocks are checks for CCM-related nodes, which
  // we want to skip until we get AMI integrated with CIAO.

  // Skip the *EventConsumer added for each eventtype.
  if (node->is_event_consumer ())
    {
      return 0;
    }

  // Check for home equivalent interface. The lookup will find the
  // home itself, which was declared first.
  Identifier *node_lname = node->AST_Decl::local_name ();
  AST_Decl *first_stored =
    node->defined_in ()->lookup_by_name_local (node_lname, false);

  if (0 != first_stored && first_stored->node_type () == AST_Decl::NT_home)
    {
      return 0;
    }

  ACE_CString lname (node_lname->get_string ());

  // Skip the *Explict and *Implicit interfaces added for a home.
  if (lname.substr (lname.length () - 6) == "plicit")
    {
      UTL_Scope *s = node->defined_in ();
      Identifier local_id (lname.substr (0, lname.length () - 8).c_str ());
      AST_Decl *d = s->lookup_by_name_local (&local_id, false);
      local_id.destroy ();

      if (0 != d)
        {
          return 0;
        }
    }

  AST_Module *module =
    AST_Module::narrow_from_scope (node->defined_in ());

  if (!module)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "module is null\n"),
                        -1);
    }

  be_interface *reply_handler = this->create_reply_handler (node);

  if (reply_handler)
    {
      reply_handler->set_defined_in (node->defined_in ());

      // Insert the ami handler after the node, the
      // exception holder will be placed between these two later.
      module->be_add_interface (reply_handler, node);

      // Remember from whom we were cloned
      reply_handler->original_interface (node);

      // If this was created for an imported node, it will be wrong
      // unless we set it.
      reply_handler->set_imported (node->imported ());
    }
  else
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "creating the reply handler failed\n"),
                        -1);
    }

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "visit scope failed\n"),
                        -1);
    }

  return 0;
}
Exemplo n.º 16
0
int
be_visitor_servant_svh::visit_consumes (be_consumes *node)
{
  if(!be_global->gen_noeventccm ())
    {
      const char *obj_name = node->consumes_type ()->full_name ();
      const char *port_name = node->local_name ()->get_string ();

      ACE_CString holder (obj_name);
      ACE_CString::size_type pos = holder.rfind (':');
      const char *ev_lname = 0;

      if (pos == ACE_CString::npos)
        {
          ev_lname = obj_name;
        }
      else
        {
          holder = holder.substr (pos + 1);
          ev_lname = holder.c_str ();
        }

      os_ << be_uidt_nl << be_nl
          << "public:" << be_idt_nl;

      os_ << "// Servant class for the " << port_name
          << " consumer." << be_nl
          << "class " << export_macro_.c_str () << " " << ev_lname
          << "Consumer_" << port_name << "_Servant" << be_idt_nl
          << ": public virtual ::POA_" << obj_name << "Consumer"
          << be_uidt_nl
          << "{" << be_nl
          << "public:" << be_idt_nl;

      ACE_CString sname_str (
        ScopeAsDecl (node_->defined_in ())->full_name ());
      const char *sname = sname_str.c_str ();
      const char *lname = node_->local_name ();
      const char *global = (sname_str == "" ? "" : "::");

      os_ << ev_lname << "Consumer_" << port_name
          << "_Servant (" << be_idt_nl
          << global << sname << "::CCM_" << lname
          << "_ptr executor," << be_nl
          << global << sname << "::CCM_" << lname
          << "_Context_ptr c);" << be_uidt_nl << be_nl;

      os_ << "virtual ~" << ev_lname << "Consumer_" << port_name
          << "_Servant (void);";

      os_ << be_nl_2
          << "virtual void" << be_nl
          << "push_" << ev_lname << " (" << be_idt_nl
          << "::" << obj_name << " * evt);" << be_uidt;

      os_ << be_nl_2
          << "/// Inherited from ::Components::EventConsumerBase." << be_nl
          << "virtual void" << be_nl
          << "push_event ( ::Components::EventBase * ev);";

      os_ << be_nl_2
          << "/// Get component implementation." << be_nl
          << "virtual ::CORBA::Object_ptr" << be_nl
          << "_get_component (void);";

      os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl;

      os_ << global << sname << "::CCM_" << lname << "_var" << be_nl
          << "executor_;";

      os_ << be_nl_2
          << global << sname << "::CCM_"
          << lname << "_Context_var" << be_nl
          << "ctx_;";

      os_ << be_uidt_nl
          << "};";

      if (!be_global->gen_lwccm ())
        {
          os_ << be_nl_2
              << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
              << "get_consumer_" << port_name << " (void);";
        }

      os_ << be_uidt_nl << be_nl
          << "private:" << be_idt_nl;

      os_ << "void" << be_nl
          << "setup_consumer_" << port_name << "_i (void);";

      os_ << be_uidt_nl << be_nl
          << "private:" << be_idt_nl;

      os_ << "::" << obj_name << "Consumer_var" << be_nl
          << "consumes_" << port_name << "_;";
    }
  return 0;
}
Exemplo n.º 17
0
void
Obj_Module::add_source(const char *p, int imports_only)
{
  ACE_Process nmproc;
  ACE_Process_Options nm_opts;
  ACE_CString path (p);

  ACE_CString::size_type pathsep = path.rfind('/');

  ACE_CString src_name;
  ACE_CString workpath;

  if (pathsep == ACE_CString::npos) {
    src_name = path;
    workpath = ".";
  } else {
    src_name = path.substr(pathsep+1);
    workpath= path.substr(0,pathsep);
  }

  ACE_HANDLE pipe[2];
  ACE_Pipe io(pipe);

  nm_opts.working_directory (workpath.c_str());
  nm_opts.set_handles (ACE_STDIN,pipe[1]);

  // Options for the command line shown here are for the GNU nm 2.9.5

  int result = nm_opts.command_line ("nm -C %s",src_name.c_str());
  // Prevent compiler warning about "unused variable" if ACE_ASSERT is
  // an empty macro.
  ACE_UNUSED_ARG (result);
  ACE_ASSERT (result == 0);

  nmproc.spawn (nm_opts);
  if (ACE_OS::close(pipe[1]) == -1)
    ACE_DEBUG ((LM_DEBUG, "%p\n", "close"));
  nm_opts.release_handles();

  int import_lines = 0;
  int export_lines = 0;
  ACE_Message_Block im_buffer (102400);
  ACE_Message_Block ex_buffer (102400);
  ACE_Message_Block *im_buf_cur = &im_buffer;
  ACE_Message_Block *ex_buf_cur = &ex_buffer;
  char dummy;
  int eoln = 1;
  //  ACE_Time_Value timeout (1,0);
  int is_import = 1;
  int is_export = 1;

  while (eoln == 1) {
    for (int i = 0; i < 10; i++) {
      if (ACE_OS::read(pipe[0],&dummy,1) != 1) {
        eoln = 2;
        break;
      }
    }
    if (eoln == 2)
      break;
    is_import = dummy == 'U';
    is_export = !imports_only && (ACE_OS::strchr("BCDRTVW",dummy) != 0);

    //    if (ACE::recv(pipe[0],&dummy,1,&timeout) != 1)
    if (ACE_OS::read(pipe[0],&dummy,1) != 1)
      break;

    eoln = this->read_line (pipe[0], is_import ? &im_buf_cur :
                            (is_export ? &ex_buf_cur : 0));
    import_lines += is_import;
    export_lines += is_export;
  }
  //  ACE_DEBUG ((LM_DEBUG, "read %d import lines and %d export lines\n",
  //            import_lines, export_lines));

  nmproc.wait ();
  ACE_OS::close (pipe[0]);

  this->populate_sig_list (imports_,import_lines,&im_buffer);
  if (!imports_only)
    this->populate_sig_list (exports_,export_lines,&ex_buffer);
}
Exemplo n.º 18
0
int
be_visitor_servant_svs::visit_consumes (be_consumes *node)
{
  AST_Type  *obj = node->consumes_type ();
  const char *port_name = node->local_name ()->get_string ();

  const char *comp_lname = node_->local_name ();
  ACE_CString comp_sname_str (
    ScopeAsDecl (node_->defined_in ())->full_name ());
  const char *comp_sname = comp_sname_str.c_str ();
  const char *global = (comp_sname_str == "" ? "" : "::");

  const char *lname = obj->local_name ()->get_string ();
  const char *fname = obj->full_name ();

  os_ << be_nl_2
      << comp_lname << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant (" << be_idt << be_idt_nl
      << global << comp_sname << "::CCM_" << comp_lname
      << "_ptr executor," << be_nl
      << global << comp_sname << "::CCM_" << comp_lname
      << "_Context_ptr c)" << be_uidt_nl
      << ": executor_ ( " << global << comp_sname << "::CCM_"
      << comp_lname << "::_duplicate (executor))," << be_idt_nl
      << "ctx_ ( " << global << comp_sname
      << "::CCM_" << comp_lname
      << "_Context::_duplicate (c))" << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "}";

  os_ << be_nl_2
      << comp_lname << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant::~" << lname << "Consumer_"
      << port_name << "_Servant (void)" << be_nl
      << "{" << be_nl
      << "}";

  os_ << be_nl_2
      << "::CORBA::Object_ptr" << be_nl
      << comp_lname << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant::_get_component (void)" << be_nl
      << "{" << be_idt_nl;

  if (ACE_OS::strcmp (be_global->ciao_container_type (), "Session") == 0)
    {
      os_ << "return this->ctx_->get_CCM_object ();";
    }
  else
    {
      os_ << "return ::CORBA::Object::_nil ();";
    }

  os_ << be_uidt_nl << "}";

  os_ << be_nl_2
      << "void" << be_nl
      << comp_lname << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant::push_" << lname
      << " (" << be_idt_nl
      << "::" << fname << " * evt)" << be_uidt_nl
      << "{" << be_idt_nl
      << "this->executor_->push_" << port_name
      << " (evt);" << be_uidt_nl
      << "}";

  os_ << be_nl_2
      << "/// Inherited from ::Components::EventConsumerBase."
      << be_nl
      << "void" << be_nl
      << comp_lname << "_Servant::" << lname << "Consumer_"
      << port_name << "_Servant::push_event (" << be_idt_nl
      << "::Components::EventBase * ev)" << be_uidt_nl
      << "{" << be_idt_nl
      << "::" << fname << " * ev_type =" << be_idt_nl
      << "::" << fname << "::_downcast (ev);"
      << be_uidt_nl << be_nl
      << "if (ev_type != 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "this->push_" << lname << " (ev_type);" << be_nl
      << "return;" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "throw ::Components::BadEventType ();" << be_uidt_nl
      << "}";

  if (!be_global->gen_lwccm ())
    {
      os_ << be_nl_2
          << "::" << fname << "Consumer_ptr" << be_nl
          << node_->local_name () << "_Servant::get_consumer_"
          << port_name << " (void)" << be_nl
          << "{" << be_idt_nl
          << "return" << be_idt_nl
          << "::" << fname << "Consumer::_duplicate (" << be_idt_nl
          << "this->consumes_" << port_name << "_.in ());"
          << be_uidt << be_uidt << be_uidt_nl
          << "}";
    }

  os_ << be_nl_2
      << "void" << be_nl
      << node_->local_name () << "_Servant::setup_consumer_"
      << port_name << "_i (void)" << be_nl
      << "{" << be_idt_nl
      << "ACE_CString obj_id (this->ins_name_);" << be_nl
      << "obj_id += \"_" << port_name << "\";" << be_nl_2
      << "::CIAO::Container_var cnt_safe =" << be_idt_nl
      << "::CIAO::Container::_duplicate ("
      << "this->container_.in ());" << be_uidt_nl << be_nl
      << "if (::CORBA::is_nil (cnt_safe.in ()))" << be_idt_nl
      << "{" << be_idt_nl << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "PortableServer::POA_var POA = cnt_safe->the_port_POA ();" << be_nl
      << node_->local_name () << "_Servant::" << lname
      << "Consumer_" << port_name << "_Servant *"
      << port_name << "_servant_impl = " << be_idt_nl
      << "new "   << node_->local_name () << "_Servant::" << lname
      << "Consumer_" << port_name << "_Servant (" << be_idt_nl
      << " this->executor_, this->context_);" << be_uidt_nl << be_uidt_nl << be_nl
      << "PortableServer::ServantBase_var safe_base_servant ("
      << port_name << "_servant_impl);" << be_nl
      << "PortableServer::ObjectId_var " << port_name << "_servant_oid =" << be_idt_nl
      << "PortableServer::string_to_ObjectId (obj_id.c_str());" << be_uidt_nl << be_nl
      << "POA->activate_object_with_id(" << be_idt_nl
      << port_name << "_servant_oid.in()," << be_nl
      <<  port_name << "_servant_impl);" << be_uidt_nl << be_nl

      << "::CORBA::Object_var " << port_name << "_servant_impl_obj = " << be_idt_nl
      << "cnt_safe->generate_reference ( " << be_idt_nl
      << "obj_id.c_str ()," << be_nl
      << "\"";

      ACE_CString work (obj->repoID ());
      ACE_CString result (work.substr (0, work.rfind (':')));
      result += "Consumer:1.0";

      os_ << result.c_str ();

      os_ << "\"," << be_nl
      << "::CIAO::Container_Types::FACET_CONSUMER_t);"
      << be_uidt_nl << be_uidt_nl
      << "::Components::EventConsumerBase_var ecb =" << be_idt_nl
      << "::Components::EventConsumerBase::_narrow ("
      << port_name << "_servant_impl_obj.in ());"
      << be_uidt_nl << be_nl
      << "this->add_consumer (\"" << port_name << "\", ecb.in ());"
      << be_uidt_nl
      << "}";

  return 0;
}
Exemplo n.º 19
0
void
Connection_Manager::load_ep_addr (const char* file_name)
{
  FILE* addr_file = ACE_OS::fopen (file_name, "r");

  if (addr_file == 0)
    {
      ACE_ERROR ((LM_DEBUG,
                  "Cannot open addr file %C\n",
                  file_name));
      return;
    }
  else
    ACE_DEBUG ((LM_DEBUG,
                "Addr file opened successfully\n"));

  while (1)
    {
      char buf [BUFSIZ];

      // Read from the file into a buffer


      /*
      int n = ACE_OS::fread (buf,
                             1,
                             BUFSIZ,
                             addr_file);
      */

      if ((ACE_OS::fgets (buf,BUFSIZ,addr_file)) == 0)
        {
          // At end of file break the loop and end the sender.
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,"End of Addr file\n"));
          break;
        }


      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "%C\n",
                    buf));

      Endpoint_Addresses* addr;
      ACE_NEW (addr,
               Endpoint_Addresses);

      TAO_Tokenizer addr_tokenizer (buf,'/');

      ACE_CString flowname;

      if (addr_tokenizer [0] == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "Corresponding flow name not specified for endpoint addresses\n"));
          return;
        }
      else
        flowname += addr_tokenizer [0];

      if (addr_tokenizer [1] != 0)
        {
          ACE_CString token (addr_tokenizer [1]);

          ACE_CString::size_type pos = token.find ('\r');
          if (pos != ACE_CString::npos)
            {
              addr->sender_addr = CORBA::string_dup ((token.substr (0, pos)).c_str ());
            }
          else
            addr->sender_addr = CORBA::string_dup (token.c_str());

          pos = addr->sender_addr.find ('\n');
          if (pos != ACE_CString::npos)
            {
              addr->sender_addr = (addr->sender_addr.substr (0, pos)).c_str ();
            }
        }

      if (addr_tokenizer [2] != 0)
        {
          ACE_CString token (addr_tokenizer [2]);

          ACE_CString::size_type pos = token.find ('\r');
          if (pos != ACE_CString::npos)
            {
              addr->receiver_addr = CORBA::string_dup ((token.substr (0,pos)).c_str ());
            }
          else
            addr->receiver_addr = CORBA::string_dup (token.c_str());

          pos = addr->receiver_addr.find ('\n');
          if (pos != ACE_CString::npos)
            {
              addr->receiver_addr = (addr->receiver_addr.substr (0, pos)).c_str ();
            }
        }

      int result = ep_addr_.bind (flowname,
                                  addr);
      if (result == 0)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        "Flowname %C Bound Successfully\n",
                        flowname.c_str ()));
        }
      else if (result == 1)
        ACE_DEBUG ((LM_DEBUG,
                    "Flowname %C already exists\n",
                    flowname.c_str ()));
      else
        ACE_DEBUG ((LM_DEBUG,
                    "Flowname %C Bound Failed\n",
                    flowname.c_str ()));
    }
}
Exemplo n.º 20
0
/*the accept function*/
static ACE_THR_FUNC_RETURN accept_step1(void *arg)
{
  /*ACE_INET_Addr addr;*/
  ACE_SOCK_Stream stream;
  ACE_HANDLE handle = (ACE_HANDLE)(intptr_t) arg;
  stream.set_handle(handle);
  if(stream.disable(ACE_NONBLOCK) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","get_remote_addr"),0);
  }
  /*
  ACE_DEBUG ((LM_INFO,
              "(%P|%t) client %s connected from %d\n",
              addr.get_host_name (),
              addr.get_port_number ()));
  */
  char* buf = new char[128];
  ACE_CString* str = new ACE_CString();
  do{
    int bytes= stream.recv(buf,128);
    ACE_DEBUG((LM_INFO,
	       "(%P|%t:%l) bytes = %d\n",bytes));
    if(bytes == -1|| bytes == 0){
      break;
    }
    for(int i=0 ;i < bytes; i++){
      *str += buf[i];
    }
  }while(true);
  delete[] buf;
  
  //the input format is '^^pqr->v1$$';
  int pos = str->find("->");
  int tail = str->find("$$");
  ACE_CString* pqr = new ACE_CString(str->substr(2,pos-2));
  ACE_CString* pv1 = new ACE_CString(str->substr(pos+2, tail - pos - 2));
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) pqr: %s\n pv1:%s\n",pqr->c_str(),pv1->c_str()));
	     
  bn* _pqr = from_hex(pqr);
  bn* _v1 = from_hex(pv1);
  bn* _pr = from_hex(&pr);
  bn* _r = npmod( _v1, _pr, _pqr);

  ACE_CString* result = _r->to_hex();
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l)pqr:%s step1:%s ", pqr->c_str(), result->c_str()));
  ACE_CString reply = ACE_CString("ack");
  stream.send(reply.c_str() , reply.length());
  stream.close();
  /*send the step1 result to hub:10007
  */
  ACE_SOCK_Connector connector;
  ACE_INET_Addr hub_addr(port,hub.c_str());
  ACE_DEBUG((LM_DEBUG,
	     "(%P|%t:%l) port:%d host:%s\n", port, hub.c_str()));
  if(connector.connect(stream, hub_addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t) connected to %s at port %d\n",
                hub_addr.get_host_name (),
                hub_addr.get_port_number ()));

  /*
   * message layout:
^^pqr->digest->senderid$$
  */
  
  ACE_CString input = ACE_CString("^^");
  input += *pqr;
  input += "->";
  input += *result;
  input += "->";
  input += id ;
  input += "$$";
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) input of step1:%s\n", input.c_str()));
  
  if(stream.send(input.c_str(),input.length()) != input.length()){
    ACE_ERROR((LM_ERROR,
	       "%p\n","send"));
  }
  stream.close();
  delete str;
  delete pqr;
  delete pv1;
  delete _pqr;
  delete _v1;
  delete _pr;
  delete _r;
  delete result;
  return 0;
}
Exemplo n.º 21
0
/*the repo function
  talk to the repo.jg.org at a regular interval, 1 minute,
  and send acknowledgement to repo.jg.org
 */
static ACE_THR_FUNC_RETURN
fetch_step2(void *){
  ACE_INET_Addr addr(repo_port, repo_host.c_str());
  ACE_SOCK_Connector con;
  ACE_SOCK_Stream stream;
  do{
  if(con.connect(stream, addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t:%l) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t:%l) connected to %s at port %d\n",
                addr.get_host_name (),
                addr.get_port_number ()));
  ACE_CString hb = ACE_CString("^^hb->");
  hb+=id+"$$";
  ACE_DEBUG((LM_INFO,
	     "%l: %s\n", hb.c_str()));
  
  stream.send(hb.c_str(),hb.length());
  stream.close_writer();
  ACE_DEBUG((LM_INFO,
	     "%l\n"));
  
  char* buf = new char[128];
  ACE_CString str;
  do{
    int bytes = stream.recv(buf,128);
    if(bytes == -1 || bytes == 0){
      break;
    }
    for(int i=0; i< bytes; i++){
      str += buf[i];
    }
  }while(true);
  delete[] buf;
  stream.close();

  ACE_CString acks = ACE_CString("^^");
  int p1=2;
  int p2= str.find("->",p1);
  int p3 = str.find("->",p2);
  int p4 = str.find("||",p3);
  node *head=NULL, *tail=NULL;
  while(p1 != -1 && p2 != -1 && p3 != -1){
    ACE_CString* pqr = new ACE_CString(str.substr(p1, p2 - p1));
    ACE_CString* v2 = new ACE_CString(str.substr(p2, p3 - p2));
    ACE_CString txn_id = str.substr(p3, p4 - p3);
    acks+="ack->"+txn_id+"||";
    node* n = new node(pqr, v2);
    if(head == NULL){
      head = n;
      tail = n;
    }else{
      tail->next = n;
      tail = n;
    }
  }
  acks+="$$";
  //  delete str;
  
  if(con.connect(stream, addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t:%l) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t:%l) connected to %s at port %d\n",
                addr.get_host_name (),
                addr.get_port_number ()));
  //send out the acks
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) %s\n",acks.c_str()));
  stream.send(acks.c_str(),acks.length());
  stream.close();
  node* tmp=head;
  //    ACE_SOCK_Connector connector;
  ACE_INET_Addr _9907addr(9907,"localhost");
  //ACE_SOCK_Stream stream;
  if(con.connect(stream, _9907addr) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "(%P|%t:%l) %p\n",
		      "connection failed"),0);
  }else
    ACE_DEBUG ((LM_DEBUG,
		"(%P|%t) connected to %s at port %d\n",
		_9907addr.get_host_name (),
		_9907addr.get_port_number ()));

  ACE_CString reply = ACE_CString("^^");
  while(tmp!=NULL){
    bn* pqr = from_hex(tmp->pqr);
    bn* v2 = from_hex(tmp->v2);
    bn* prv = from_hex(&pr);
    bn* res = npmod(v2,prv,pqr);
    ACE_CString* resStr = res->to_hex();
    /*send the output to localhost:9907*/
    reply += tmp->pqr->c_str();
    reply += "->" + *resStr + "||";
    ACE_DEBUG((LM_DEBUG,
	       "(%P|%t) %s\n",reply.c_str()));
    delete pqr;
    delete v2;
    delete prv;
    delete res;
    delete resStr;
    tmp = tmp->next;
  }
  reply += "$$";
  stream.send(reply.c_str(),reply.length());
  stream.close();
  reclaim_node(head);
  /*sleep for 1 second, for the next poll;*/
  ACE_OS::sleep(1000);
  }while(true);
  //  delete str;
}
Exemplo n.º 22
0
Arquivo: ami_cs.cpp Projeto: manut/TAO
int
be_visitor_operation_ami_cs::visit_operation (be_operation *node)
{
  // No sendc method for oneway operations.
  if (node->flags () == AST_Operation::OP_oneway)
    {
      return 0;
    }

  be_visitor_context ctx;
  TAO_OutStream *os = this->ctx_->stream ();
  this->ctx_->node (node);

  *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__;

  // Generate the return type mapping. Return type is simply void.
  *os << be_nl_2
      << "void" << be_nl;

  // Generate the operation name.

  // Grab the scope name.
  be_decl *parent =
    be_scope::narrow_from_scope (node->defined_in ())->decl ();

  if (parent == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_ami_cs::"
                         "visit_operation - "
                         "scope name is nil\n"),
                        -1);
    }

  // Generate the scope::operation name.
  *os << parent->full_name ()
      << "::" << this->ctx_->port_prefix ().c_str ()
      << node->local_name ()->get_string ();

  // Generate the argument list with the appropriate mapping (same as
  // in the header file)
  ctx = *this->ctx_;
  be_visitor_operation_arglist oa_visitor (&ctx);

  // Get the AMI version from the strategy class.
  be_operation *ami_op = node;

  if (ami_op->accept (&oa_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_ami_cs::"
                         "visit_operation - "
                         "codegen for argument list failed\n"),
                        -1);
    }

  // Generate the actual code for the stub. However, if any of the argument
  // types is "native", we flag a MARSHAL exception.
  // last argument
  *os << be_nl << "{" << be_idt;

  if (node->has_native ()) // native exists => no stub
    {
      be_predefined_type bpt (AST_PredefinedType::PT_void,
                              0);

      int const status = this->gen_raise_exception ("::CORBA::MARSHAL",
                                                    "");

      if (status == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_ami_cs::"
                             "visit_operation - "
                             "codegen for has-native exception failed\n"),
                            -1);
        }
    }
  else
    {
      *os << be_nl
          << "if (!this->is_evaluated ())" << be_idt_nl
          << "{" << be_idt_nl
          << "::CORBA::Object::tao_object_initialize (this);"
          << be_uidt_nl
          << "}" << be_uidt_nl << be_nl;
    }

  // Includes the reply handler, but we have to add 1 for the retval anyway.
  int nargs = ami_op->argument_count ();

  if (nargs == 1)
    {
      // No arguments other than the reply handler, and the return
      // type is void.  No need to generate argument list.

      *os << be_nl_2
          << "TAO::Argument ** _the_tao_operation_signature = 0;";
      nargs = 0; // Don't count the reply handler.
    }
  else
    {
      *os << be_nl<< be_nl
          << "TAO::Arg_Traits<void>::"
          << (node->flags () == AST_Operation::OP_oneway &&
              be_global->use_clonable_in_args() ? "clonable_" : "")
          << "ret_val _tao_retval;";

      // Declare the argument helper classes.
      this->gen_stub_body_arglist (ami_op, os, true);

      // Assemble the arg helper class pointer array.
      *os << be_nl_2
          << "TAO::Argument *_the_tao_operation_signature[] =" << be_idt_nl
          << "{" << be_idt_nl
          << "&_tao_retval";

      AST_Argument *arg = 0;
      UTL_ScopeActiveIterator arg_list_iter (ami_op,
                                             UTL_Scope::IK_decls);

      // For a sendc_* operation, skip the reply handler (first argument).
      arg_list_iter.next ();

      for (; ! arg_list_iter.is_done (); arg_list_iter.next ())
        {
          arg = AST_Argument::narrow_from_decl (arg_list_iter.item ());

          *os << "," << be_nl
              << "&_tao_" << arg->local_name ();
        }

      *os << be_uidt_nl
          << "};" << be_uidt;
    }

  ACE_CString base (node->local_name ()->get_string ());

  /// The sendc_* operation makes the invocation with the
  /// original operation name.
  ACE_CString lname_str (base.substr (ACE_OS::strlen ("sendc_")));
  const char *lname = lname_str.c_str ();

  ACE_CString opname (node->is_attr_op () ? "_" : "");
  opname += lname;

  /// Some compilers can't resolve the stream operator overload.
  const char *op_name = opname.c_str ();
  ACE_CDR::ULong len = opname.length ();

  *os << be_nl_2
      << "TAO::Asynch_Invocation_Adapter _tao_call (" << be_idt << be_idt_nl
      << "this," << be_nl
      << "_the_tao_operation_signature," << be_nl
      << nargs << "," << be_nl
      << "\"" << op_name << "\"," << be_nl
      << len << "," << be_nl;

  *os << "TAO::TAO_CO_NONE";
  if (be_global->gen_direct_collocation())
    {
      *os << " | TAO::TAO_CO_DIRECT_STRATEGY";
    }
  if (be_global->gen_thru_poa_collocation())
    {
      *os << " | TAO::TAO_CO_THRU_POA_STRATEGY";
    }

  *os << be_uidt_nl
      << ");" << be_uidt;

  *os << be_nl_2
      << "_tao_call.invoke (" << be_idt << be_idt_nl
      << "ami_handler," << be_nl
      << "&";

  if (parent->is_nested ())
    {
      be_decl *gparent =
        be_scope::narrow_from_scope (parent->defined_in ())->decl ();

      *os << gparent->name () << "::";
    }

  *os << "AMI_"  << parent->local_name () << "Handler::"
      << lname << "_reply_stub" << be_uidt_nl
      << ");" << be_uidt;

  *os << be_uidt_nl
      << "}";

  return 0;
}
Exemplo n.º 23
0
// Given a comma separated list of preferred interface directives, which
// are of the form <wild_remote>=<wild_local>, this function will retrieve
// the list of preferred local ip addresses by matching wild_local against
// the list of all local ip interfaces, for any directive where wild_remote
// matches the host from our endpoint.
void
TAO_IIOP_Endpoint::find_preferred_interfaces (
  const ACE_CString &host,
  const ACE_CString &csvPreferred,
  ACE_Vector<ACE_CString> &preferred)
{
  ACE_Vector<ACE_CString> local_ips;
  TAO_IIOP_Endpoint_get_ip_interfaces (local_ips);
  if (local_ips.size () == 0)
    return;

  // The outer loop steps through each preferred interface directive
  // and chains a new endpoint if the remote interface matches the
  // current endpoint.
  ACE_CString::size_type index = 0;
  while (index < csvPreferred.length ())
    {
      ACE_CString::size_type comma = csvPreferred.find (',', index);
      ACE_CString::size_type assign = csvPreferred.find ('=', index);

      if (assign == ACE_CString::npos)
        {
          assign = csvPreferred.find (':', index);
          if (assign == ACE_CString::npos)
            {
              ACE_ASSERT (assign != ACE_CString::npos);
              return;
            }
        }

      ACE_CString wild_local;
      if (comma == ACE_CString::npos)
        wild_local = csvPreferred.substr (assign + 1);
      else
        wild_local = csvPreferred.substr (assign + 1, comma - assign - 1);
      ACE_CString wild_remote = csvPreferred.substr (index, assign - index);
      index = comma + 1;

      // For now, we just try to match against the host literally. In
      // the future it might be worthwhile to resolve some aliases for
      // this->host_ using DNS (and possibly reverse DNS) lookups. Then we
      // could try matching against those too.
      if (ACE::wild_match (host.c_str (), wild_remote.c_str (), false))
        {
          // If it's a match, then it means we need to use any/all
          // local interface(s) that matches wild_local.
          const char *const wild_local_cstr =  wild_local.c_str ();
          bool found= false;
          for (size_t i = 0u; i < local_ips.size (); ++i)
            {
              ACE_CString &ret = local_ips[i];
              if (ACE::wild_match (ret.c_str (), wild_local_cstr))
                {
                  found= true;
                  TAO_IIOP_Endpoint_none_duplicate_insert (ret, preferred);
                }
            }

          if (!found)
            {
#if defined (ACE_HAS_IPV6)
              // We interpret the preferred wild_local as an actual interface name/id.
              // This is useful for link local IPv6 multicast

              ACE_CString if_name ("if=");
              if_name += wild_local;
              TAO_IIOP_Endpoint_none_duplicate_insert (if_name, preferred);
#else
              // There is no matching local interface, so we can skip
              // to the next preferred interface directive.
#endif
            }
        }
      else
        {
          // The preferred interface directive is for a different
          // remote endpoint.
        }
      if (comma == ACE_CString::npos)
        break;
    }
}
Exemplo n.º 24
0
// receive the heartbeat information, and return back the enquened messages;
static ACE_THR_FUNC_RETURN
commu(void* arg){
  ACE_INET_Addr addr;
  ACE_SOCK_Stream stream;
  ACE_HANDLE handle =(ACE_HANDLE)(intptr_t) arg;
  stream.set_handle(handle);
  if(stream.disable(ACE_NONBLOCK) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","disable"),0);
  }
  else if(stream.get_remote_addr(addr)== -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","get_remote_addr"),0);
  }
  ACE_DEBUG((LM_INFO,
	     "(%P|%t) client %s connected from %d\n",
	     addr.get_host_name(),addr.get_port_number()));
  ACE_CString str ;
  char* ch = new char[128];  
  do{
    int bytes = stream.recv(ch, 128);
    if(bytes == -1){
      ACE_ERROR((LM_ERROR,
		 "%p\n","recv"));
      break;
    }
    if(bytes == 0){
      ACE_DEBUG((LM_INFO,
		 "(%P|%t) reached end of input, connection closed by client\n"));
      break;
    }
    for(int i = 0; i< bytes; i++){
      str += ch[i];
    }
  }while(true);
  delete[] ch;
  ACE_DEBUG((LM_INFO,
	     "received message:%s\n", str.c_str()));
  
  /*
    the layout of the heartbeat message:
    ^^hb->senderid$$
   */
  /*if got a heartbeat message*/
  int pos = str.find("^^hb->");
  if( pos >= 0 ){
    int p2 = str.find("$$");
    ACE_CString id= str.substr(6, p2 -6);
    //    delete str;
    ACE_CString sql = "select pqr, v2,txn_id from step2 where recipient='"+ id +"' and transmitted='false' ";
    ACE_DEBUG((LM_DEBUG,
	       "%s\n", sql.c_str()));
    PGconn* con;
    PGresult* res;
    con = PQconnectdb("dbname=pq");
    if(PQstatus(con)!= CONNECTION_OK){
      ACE_DEBUG((LM_INFO,
		 "Connection to database failed:%s\n",
		 PQerrorMessage(con)));
      reclaim_conn(con);
    }
    res = PQexec(con, sql.c_str());
    int n = PQntuples(res);
    if(n == 0){
      /*no pending messages at all, exit immediately*/
      ACE_DEBUG((LM_INFO,
		 "(%P|%t) no pending messages at all\n"));
      PQclear(res);
      reclaim_conn(con);
      stream.close();
      //      delete str;
      return 0;
  }
    /*there are pending messages*/
    else{
      /* the reply message is in format "^^pqr1->v1->txn_id1||pqr2->v2->txn_id2||pqr3->v3->txn_id3||$$"*/
      ACE_CString reply = ACE_CString("^^");
      for(int i=0; i < n ; i++){
	reply += PQgetvalue(res, i, 0);
	reply += "->";
	reply += PQgetvalue(res, i, 1);
	reply += "->";
	reply += PQgetvalue(res, i, 2);
	reply += "||";
      }
      reply += "$$";
      PQclear(res);
      /*    reclaim_conn(con);
       */
      stream.send(reply.c_str(), reply.length());
      ACE_DEBUG((LM_INFO,
		 "(%P|%t:%l) %s\n", reply.c_str()));
      ACE_DEBUG((LM_INFO,
		 "(%P|%t) close the writer\n"));
      stream.close();
      //      delete str;
      return 0;
    }
  }
  
  /*if got an ack message
    '^^ack->txn_id2||ack->txn_id2||$$'
   */
  int p = str.find("^^ack->");
  if( p >= 0){
    PGconn* con;
    PGresult* res;
    con = PQconnectdb("dbname=pq");
    if(PQstatus(con)!= CONNECTION_OK){
      ACE_DEBUG((LM_INFO,
		 "Connection to database failed:%s\n",
		 PQerrorMessage(con)));
      reclaim_conn(con);
    }
    do{
      p += 7;
      int p2 = str.find("||",p);
      if(p2< 0){
	ACE_DEBUG((LM_INFO,
		   "reached the end of the txn_ids\n"));
	break;
      }
      ACE_CString txn_id = str.substr(pos, p2 - p);
      ACE_CString sql = ACE_CString("update step2 set transmitted=TRUE where txn_id='");
      sql += txn_id;
      sql += "'";
      ACE_DEBUG((LM_INFO,
	       "(%P|%t:%l) sql:%s\n" , sql.c_str()));
      res = PQexec(con, sql.c_str());
      PQclear(res);
      p = p2;
    }while(true);
    reclaim_conn(con);
    stream.close();
    //    delete str;
    return 0;
  }
  return 0;
}
Exemplo n.º 25
0
// Parse arguments on command line
void
DRV_parse_args (long ac, char **av)
{
  ACE_CString buffer;
  char *s = 0;
  long i;
  bool has_space = false;

  FE_store_env_include_paths ();
  DRV_cpp_init ();
  idl_global->set_prog_name (av[0]);

  for (i = 1; i < ac; i++)
    {
      if (av[i][0] == '-')
        {
          idl_global->append_idl_flag (av[i]);

          switch (av[i][1])
            {
            case 0:
              // One or more letters expected after the dash.
              ACE_ERROR ((
                  LM_ERROR,
                  ACE_TEXT ("IDL: Space between dash and option ")
                  ACE_TEXT ("letters not allowed\n")
                ));

              ++i;
              idl_global->set_err_count (idl_global->err_count () + 1);
              break;
            case 'A':
              if (av[i][2] == '\0')
                {
                  if (i < ac - 1)
                    {
                      s = av[i + 1];
                      ++i;
                    }
                  else
                    {
                      ACE_ERROR ((
                          LM_ERROR,
                          ACE_TEXT ("IDL: incorrect use of ")
                          ACE_TEXT ("the -A option\n")
                        ));

                      idl_global->set_compile_flags (
                                      idl_global->compile_flags ()
                                      | IDL_CF_ONLY_USAGE
                                    );
                      break;
                    }
                }
              else
                {
                  s = av[i] + 2;
                }

              ACE_OS::strcat (idl_global->local_escapes (), s);
              ACE_OS::strcat (idl_global->local_escapes (), " ");
              break;
            case 'a':
              if (av[i][2] == 'e')
                {
                  idl_global->anon_type_diagnostic (
                    IDL_GlobalData::ANON_TYPE_ERROR);
                }
              else if (av[i][2] == 'w')
                {
                  idl_global->anon_type_diagnostic (
                    IDL_GlobalData::ANON_TYPE_WARNING);
                }
              else if (av[i][2] == 's')
                {
                  idl_global->anon_type_diagnostic (
                    IDL_GlobalData::ANON_TYPE_SILENT);
                }
              else
                {
                  ACE_ERROR ((
                      LM_ERROR,
                      ACE_TEXT ("IDL: I don't understand")
                      ACE_TEXT (" the '%s' option\n"),
                      ACE_TEXT_CHAR_TO_TCHAR (av[i])
                    ));
                 }

               break;
            // Temp directory for the IDL compiler to keep its files.
            case 't':
              if ((av[i][2] == '\0') && (i < ac - 1))
                {
                  idl_global->append_idl_flag (av[i + 1]);
                  idl_global->temp_dir (av[i + 1]);
                  ++i;
                }
              else
                {
                  ACE_ERROR ((
                      LM_ERROR,
                      ACE_TEXT ("IDL: I don't understand")
                      ACE_TEXT (" the '%s' option\n"),
                      ACE_TEXT_CHAR_TO_TCHAR (av[i])
                    ));

                  idl_global->set_compile_flags (
                                  idl_global->compile_flags ()
                                  | IDL_CF_ONLY_USAGE
                                );
                }

              break;
            case 'D':
            case 'U':
            case 'I':
              if (av[i][2] == '\0')
                {
                  if (i < ac - 1)
                    {
                      idl_global->append_idl_flag (av[i + 1]);
                      has_space = FE_Utils::hasspace (av[i + 1]);

                      // If the include path has a space, we need to
                      // add literal "s.
                      ACE_CString arg = av[i];
                      arg += (has_space ? "\"" : "");
                      arg += av[i + 1];
                      arg += (has_space ? "\"" : "");

                      DRV_cpp_putarg (arg.c_str ());
                      idl_global->add_include_path (arg.substr (2).c_str (), false);
                      ++i;
                    }
                  else
                    {
                      ACE_ERROR ((
                          LM_ERROR,
                          ACE_TEXT ("IDL: I don't understand")
                          ACE_TEXT (" the '%s' option\n"),
                          ACE_TEXT_CHAR_TO_TCHAR (av[i])
                        ));

                      idl_global->set_compile_flags (
                                      idl_global->compile_flags ()
                                      | IDL_CF_ONLY_USAGE
                                    );
                      break;
                    }
                }
              else
                {
                  has_space = FE_Utils::hasspace (av[i]);

                  // If the include path has a space, we need to
                  // add literal "s.
                  ACE_CString arg (av[i], 2);
                  arg += (has_space ? "\"" : "");
                  arg += av[i] + 2;
                  arg += (has_space? "\"" : "");

                  idl_global->add_include_path (arg.substr (2).c_str (), false);
                  DRV_cpp_putarg (arg.c_str ());
                }

              break;
            case 'E':
              idl_global->set_compile_flags (idl_global->compile_flags () |
                                             IDL_CF_ONLY_PREPROC);
              break;
            case 'V':
              idl_global->set_compile_flags (idl_global->compile_flags () |
                                             IDL_CF_VERSION);
              break;
            case 'W':
              if (av[i][2] == '\0')
                {
                  if (i < ac - 1)
                    {
                      s = av[i + 1];
                      ++i;
                    }
                  else
                    {
                      ACE_ERROR ((
                          LM_ERROR,
                          ACE_TEXT ("IDL: I don't understand")
                          ACE_TEXT (" the '%s' option\n"),
                          ACE_TEXT_CHAR_TO_TCHAR (av[i])
                        ));

                      idl_global->set_compile_flags (
                                      idl_global->compile_flags ()
                                      | IDL_CF_ONLY_USAGE
                                    );
                      break;
                    }
                }
              else
                {
                  s = av[i] + 2;
                }

              switch (*s)
                {
                default:
                  ACE_ERROR ((
                      LM_ERROR,
                      ACE_TEXT ("IDL: Incorrect use of -W option\n")
                    ));

                  idl_global->set_compile_flags (
                                  idl_global->compile_flags ()
                                  | IDL_CF_ONLY_USAGE
                                );
                  break;
                case 'p':
                  if (*(s + 1) == ',')
                    {
                      DRV_prep_cpp_arg (s + 2);
                    }

                  break;
                case 'b':
                  if (*(s + 1) == ',')
                    {
                      be_util::prep_be_arg (s + 2);
                    }

                  break;
                }

              break;
            case 'Y':
              if (av[i][2] == '\0')
                {
                  if (i < ac - 1)
                    {
                      s = av[i + 1];
                      ++i;
                    }
                  else
                    {
                      ACE_ERROR ((
                          LM_ERROR,
                          ACE_TEXT ("IDL: I don't understand")
                          ACE_TEXT (" the '%s' option\n"),
                          ACE_TEXT_CHAR_TO_TCHAR (av[i])
                        ));

                      idl_global->set_compile_flags (
                                      idl_global->compile_flags ()
                                      | IDL_CF_ONLY_USAGE
                                    );
                      break;
                    }
                }
              else
                {
                  s = av[i] + 2;
                }

              switch (*s)
                {
                  case 'p':
                    if (*(s + 1) == ',')
                      {
                        idl_global->set_cpp_location (s + 2);
                        DRV_cpp_new_location (s + 2);
                      }
                    else
                      {
                        ACE_ERROR ((
                            LM_ERROR,
                            ACE_TEXT ("IDL: I don't understand")
                            ACE_TEXT (" the '-Y' option\n")
                          ));

                        idl_global->set_compile_flags (
                                        idl_global->compile_flags ()
                                        | IDL_CF_ONLY_USAGE
                                      );
                      }

                    break;
                  default:
                    ACE_ERROR ((
                        LM_ERROR,
                        ACE_TEXT ("IDL: I dont' understand the use of")
                        ACE_TEXT (" %s with the '-Y' option\n"),
                        ACE_TEXT_CHAR_TO_TCHAR (s)
                      ));

                    idl_global->set_compile_flags (
                                    idl_global->compile_flags ()
                                    | IDL_CF_ONLY_USAGE
                                  );
                   break;
                }
              break;
            case 'd':
              idl_global->set_compile_flags (idl_global->compile_flags ()
                                             | IDL_CF_DUMP_AST);
              break;
            case 'u':
              idl_global->set_compile_flags (idl_global->compile_flags ()
                                             | IDL_CF_ONLY_USAGE);
              break;
            case 'v':
              idl_global->set_compile_flags (idl_global->compile_flags ()
                                             | IDL_CF_INFORMATIVE);
              break;
            case 'w':
              idl_global->set_compile_flags (idl_global->compile_flags ()
                                             | IDL_CF_NOWARNINGS);
              break;
            case 'C':
              // If identifiers in the same scope differ only by case...
              if (av[i][2] == 'e')
                {
                  // ...report an error.
                  idl_global->case_diff_error (true);
                }
              else if (av[i][2] == 'w')
                {
                  // ...report a warning (default for now)
                  idl_global->case_diff_error (false);
                }
              else
                {
                  ACE_ERROR ((
                      LM_ERROR,
                      ACE_TEXT ("IDL: I don't understand the '%s' option\n"),
                      ACE_TEXT_CHAR_TO_TCHAR (av[i])
                    ));

                  idl_global->set_compile_flags (
                                  idl_global->compile_flags ()
                                  | IDL_CF_ONLY_USAGE
                                );
                }

              break;
            default:
              be_global->parse_args (i, av);
              break;
            } // End of switch (av[i][1])
        } // End of IF (av[i][0] == '-')
      else
        {
          DRV_push_file (av[i]);
        }
    } // End of FOR (i = 1; i < ac; i++)

  be_util::arg_post_proc ();

  // Make sure the output directory is valid.
  if (idl_global->temp_dir () == 0)
    {
      ACE_TCHAR tmpdir[MAXPATHLEN + 1];

      if (ACE::get_temp_dir (tmpdir, MAXPATHLEN) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Temporary path too long, ")
                      ACE_TEXT ("defaulting to current directory\n")));

          ACE_OS::strcpy (tmpdir, ACE_TEXT ("."));
        }

#if defined(ACE_MVS)
      if (ACE_OS::access (tmpdir, F_OK) == -1
          || ACE_OS::access (tmpdir, R_OK) == -1
          || ACE_OS::access (tmpdir, W_OK) == -1)
#else
      if (ACE_OS::access (tmpdir, F_OK | R_OK | W_OK) == -1)
#endif /* ACE_MVS */
        {
          ACE_ERROR ((
              LM_ERROR,
              ACE_TEXT ("Can't access temporary directory (%s),")
              ACE_TEXT (" using current directory for temp files.\n"),
              tmpdir
            ));

          ACE_OS::strcpy (tmpdir, ACE_TEXT ("."));
#if defined(ACE_MVS)
          if (ACE_OS::access (tmpdir, F_OK) == -1
              || ACE_OS::access (tmpdir, R_OK) == -1
              || ACE_OS::access (tmpdir, W_OK) == -1)
#else
          if (ACE_OS::access (tmpdir, F_OK | R_OK | W_OK) == -1)
#endif /* ACE_MVS */
            {
              ACE_ERROR ((LM_ERROR,
                          "Error: Can't access temporary directory %s\n",
                          tmpdir));

              throw Bailout ();
            }
        }

      idl_global->temp_dir (ACE_TEXT_ALWAYS_CHAR (tmpdir));
    }

  DRV_cpp_post_init ();
}