Ejemplo n.º 1
0
  /*! 
   * private function, DO NOT CALL DIRECTLY 
   */
  void SamgarModule::SendData(DataType type,string port,void* data) {
    DataPort* MyTempPort;
    list<DataPort*>::iterator ItPort;
    string TempName;
    bool FoundPort;

    TempName="/Port_" + MyName + "_" + port.c_str();

    FoundPort=false;
    for ( ItPort=PortList.begin() ; ItPort != PortList.end(); ItPort++ ) {
      MyTempPort=*ItPort;
      if(MyTempPort->getName() == TempName.c_str()) {
	FoundPort=true;
	break; // we have the port so break the loop
      }
    }
    if(FoundPort==true) {
      Bottle& MyBottle = MyTempPort-> prepare();
      MyBottle.clear();
      switch (type){
      case TypeInt:    MyBottle.addInt( *((int*) data) ); break;
      case TypeDouble: MyBottle.addDouble( *((double*) data) ); break;
      case TypeString: MyBottle.addString( ((string*) data)->c_str()); break;
      case TypeBottle: MyBottle = *((Bottle*)data); break;
      }
      MyTempPort->write();
    }
  }
Ejemplo n.º 2
0
  /*! 
   * DO NOT CALL DIRECTLY 
   */
  bool SamgarModule::GetDataFromPort(string NameOfPort,int TypeOfData, void* data) {
    list<DataPort*>::iterator ItPort;
    DataPort *MyTempPort;
    bool HaveIfoundPort;
  
    NameOfPort = "/Port_" + MyName + "_" + NameOfPort.c_str();
    HaveIfoundPort = false;

    for ( ItPort=PortList.begin(); ItPort != PortList.end(); ItPort++ ) {// find the right port loop
      MyTempPort=*ItPort;
      if(MyTempPort->getName() == NameOfPort.c_str()){
	HaveIfoundPort = true;
	break;
      }// have the data we need so break the loop
    }

    if ( !HaveIfoundPort )
	return false;

    if (MyTempPort->isClosed())
        return false;

    if(MyTempPort->getInputCount() == 0)
      return false; // if nothings connected to it  	

    // gets Bottle from  the DataPort storage
    Bottle MyBottle=MyTempPort->getBottle();

      if(MyBottle.isNull())
	return false;
    
      if (TypeOfData == TypeInt && MyBottle.get(0).isInt() != false) {
	*((int*)data) = MyBottle.get(0).asInt();
	return true;
      }
      else if (TypeOfData == TypeString && MyBottle.get(0).isString() != false) {
	*((string*)data) = MyBottle.get(0).asString();
	return true;
      }
      else if(TypeOfData == TypeDouble && MyBottle.get(0).isDouble() != false) {
	*((double*)data) = MyBottle.get(0).asDouble();
	return true;
      }
      else if(TypeOfData == TypeBottle) {
	*((Bottle*)data) = MyBottle;
	return true;
      }
    return false;
  }