示例#1
0
typename ContainerBuilder::RegistrationBuilderInterface< T >::Type&
ContainerBuilder::autowireType()
{
    typedef typename T::AutowiredSignature AutowiredSignature;
    static_assert(AutowiredSignature::IsSignatureRecognized::value, "Unable to use this autowired constructor.");

    auto rb = RegistrationBuilderFactory< ContainerBuilder::RegistrationBuilderInterface >::forDelegate(AutowiredSignature::createDelegate());

    registerCallback(
        [rb](const std::shared_ptr< IComponentRegistry >& cr)
    {
        RegistrationBuilderFactory< ContainerBuilder::RegistrationBuilderInterface >::registerSingleComponent< T >(cr, rb);
    });

    return *rb;
}
示例#2
0
// Start the conduit working
bool SimpleConduit::initialize(){ 
    
    EventTransport::event_transport_directionality directionality = transport->getDirectionality();
    if(directionality == EventTransport::read_only_event_transport ||
       directionality == EventTransport::bidirectional_event_transport){
        
        // start a read thread to receive events and dispatch callbacks
        read_thread = boost::thread(boost::bind(&SimpleConduit::serviceIncomingEvents, this));
    }
    
    running = true;
    
    // register to receive control events
    // this is needed to be able to handshake regarding time offsets
    registerCallback(RESERVED_SYSTEM_EVENT_CODE, bind(&SimpleConduit::handleSystemEvent, this, _1));
    
    // send a "connected" event to the other side of the conduit
    sendData(SystemEventFactory::connectedEvent());
    
    return true;
}
示例#3
0
    std::shared_ptr< typename ContainerBuilder::RegistrationBuilderInterface< T >::Type >
    ContainerBuilder::registerInstance(std::shared_ptr< T > instance)
    {
        static_assert(!std::is_pod< T >::value || std::is_empty< T >::value || std::is_class< T >::value,
                      "ContainerBuilder::registerType< T >(std::shared_ptr< T > instance) is incompatible with POD types.");

        auto rb = RegistrationBuilderFactory< ContainerBuilder::RegistrationBuilderInterface >::forInstance(instance);

        rb->singleInstance();

        registerCallback(
            [rb](std::shared_ptr< IComponentRegistry > cr) -> void
            {
                auto rootScopeLifetime = std::dynamic_pointer_cast< RootScopeLifetime >(rb->registrationData().lifetime());
                if (rootScopeLifetime == nullptr || rb->registrationData().sharing() != InstanceSharing::Shared)
                    throw std::logic_error("Instance registration is single instance only.");

                RegistrationBuilderFactory< ContainerBuilder::RegistrationBuilderInterface >::registerSingleComponent< T >(cr, rb);
            });

        return rb;
    }
示例#4
0
instrCodeNode_Val::instrCodeNode_Val(const instrCodeNode_Val &par,
				     pd_process *childProc) :
  name(par.name), focus(adjustFocusForPid(par.focus, childProc->getPid())),
  instrLoaded_(par.instrLoaded_), 
  instrDeferred_(par.instrDeferred_), instrCatchuped_(par.instrCatchuped_),
  proc_(childProc),
  hwEvent(par.hwEvent), pendingDeletion(par.pendingDeletion),
  numCallbacks(0)
{
   if(par.sampledDataNode)
      sampledDataNode = new instrDataNode(*par.sampledDataNode, childProc);
   else sampledDataNode = NULL;

   if(par.constraintDataNode)
      constraintDataNode = new instrDataNode(*par.constraintDataNode, 
                                             childProc);
  else constraintDataNode = NULL;
   
   for(unsigned i=0; i<par.tempCtrDataNodes.size(); i++) {
      tempCtrDataNodes.push_back(new instrDataNode(*(par.tempCtrDataNodes[i]), 
                                                   childProc));
   }

   for(unsigned j=0; j<par.instRequests.size(); j++) {
      instReqNode *newInstReq = new instReqNode(*par.instRequests[j], 
                                                childProc);
      instRequests.push_back(newInstReq);
      if (newInstReq->instrLoaded()) {
         // update the data assocated with the minitramp deletion callback
         pdvector<instrDataNode *> affectedNodes;
         getDataNodes(&affectedNodes);
         for (unsigned i = 0; i < affectedNodes.size(); i++) {
            affectedNodes[i]->incRefCount();
         }
	 registerCallback(newInstReq);
      }
   }
   referenceCount = 0;  // this node when created, starts out unshared
}
示例#5
0
int BACIComponent::registerAction(const BACIValue::Type type,
				  Callback_ptr callback_p,
				  const CBDescIn descIn,
				  ActionImplementator* actionImplementator_p,
				  int actionFunction,
				  const BACIValue& value)
{
  ACS_TRACE("baci::BACIComponent::registerAction");

  int callbackID = registerCallback(type, callback_p, descIn);
  if (callbackID==0)
      {
      return 0;
      }

  BACIAction* action_p = new BACIAction(actionImplementator_p, actionFunction, callbackID, value);
  if (action_p==0)
    {
      removeCallback(callbackID);
      return 0;
    }
  pushAction(action_p);
  return callbackID;
}
MStatus liqIPRNodeMessage::doIt( const MArgList& args)
//
// Takes the  nodes that are on the active selection list and adds an
// attriubte changed callback to each one.
//
{	
	MStatus 		stat;

	for( unsigned i( 0 ); i < args.length(); i++ ) 
	{
		MString arg = args.asString( i, &stat );
		IfMErrorWarn(stat);

		if( (arg == kRegisterFlag) || (arg == kRegisterFlagLong) ){
			isRunningIPR = 1;
			liqRibTranslator::getInstancePtr()->IPRRenderBegin();
			IfMErrorWarn(registerCallback());
			//liqRibTranslator::getInstancePtr()->IPRDoIt();
		}
		else if( (arg == kUnregisterFlag) || (arg == kUnregisterFlagLong) ){
			IfMErrorWarn(unregisterCallback());

			liqRibTranslator::getInstancePtr()->IPRRenderEnd();
			isRunningIPR = 0;
		}
		else if( (arg == kIsRunningIPR) || (arg == kIsRunningIPRLong) ){
			setResult(isRunningIPR);
		}
		else{
			liquidMessage2(messageError,"Parameter [%s] is undefined in liqIPRNodeMessage.", arg.asChar());
			return MS::kUnknownParameter;
		}
	}

	return MS::kSuccess;
}
示例#7
0
 DGTProcessor(LTFAT_FIRWIN win, int gl, int a, int M, int Wmax, DGTProcessor::Callback callback):
     DGTProcessor(win, gl, a, M, Wmax)
 {
     registerCallback(callback);
 }
示例#8
0
void TriggerCentral::addEventListener(ShaftPositionListener listener, const char *name, Engine *engine) {
	print("registerCkpListener: %s\r\n", name);
	registerCallback(&triggerListeneres, (IntListener) listener, engine);
}
 void registerCallback(int signum, const FuncType& callBack, const std::string& name)
 {
     registerCallback(std::initializer_list<int>{signum}, callBack, name);
 }
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::setup(int cameraID){
        if( theCamera != NULL || theCameraList != NULL){
            destroy();
        }

        EdsError err = EDS_ERR_OK;
        EdsUInt32 cameraCount = 0 ;

        err = EdsInitializeSDK();

        if(err != EDS_ERR_OK){
           printf("Couldn't open sdk!\n");
            return false;
        }else{
            printf("Opening the sdk\n");
            sdkRef++;
        }
		
		ofSleepMillis(3000);

        // Initialize
        // Get the camera list
        err = EdsGetCameraList(&theCameraList);

        // Get the number of cameras.
        if( err == EDS_ERR_OK ){
            err = EdsGetChildCount( theCameraList, &cameraCount );
            if ( cameraCount == 0 ){
                err = EDS_ERR_DEVICE_NOT_FOUND;
                printf("No devices found!\n");
                return false;
            }
        }

        // Get the camera
        if ( err == EDS_ERR_OK ){
            if (cameraID >= cameraCount){
                printf("No camera of id %i exists - number of cameras is %i\n", cameraID, cameraCount);
                return false;
            }

            printf("We are opening camera %i!\n", cameraID);

            err = EdsGetChildAtIndex( theCameraList , cameraID , &theCamera );
			
			//Release camera list
			if(theCameraList != NULL){
				EdsRelease(theCameraList);
			}
			
            if(err == EDS_ERR_OK){
                printf("We are connected!\n");
                state = CAMERA_READY;
                //return true;
            }else{
                printf("We are not connected!\n");
                state = CAMERA_UNKNOWN;
                return false;
            }
			
            registerCallback();		
			return true;			
        }
    }
示例#11
0
void Puck::_register(){
  registerCallback( &Puck::callback, (void*)this);	
}
示例#12
0
文件: main.cpp 项目: Chris112/sep
int main(int argc, char **argv)
{
    if(argc != 6) {
        std::cout << "wrong args" << std::endl;
        return 1;
    }
    const char *sensorDeviceName = argv[1];
    const char *actuatorDeviceName = argv[2];
    const int cameraDeviceNum = atoi(argv[3]);
    const int port = atoi(argv[4]);
    const char *mode = argv[5];

    bool showThermal = false;
    bool showRGB = false;
    if(mode[0] == 't') {
        showThermal = true;
    } else if(mode[0] == 'r') {
        showRGB = true;
    } else {
        throw "wtf";
    }

    std::cout << "blah" << std::endl;

    std::shared_ptr<ApplicationCore> core = ApplicationCore::instantiate();

    auto sc = std::make_shared<ThermalSensorController>(core, sensorDeviceName, 115200);
    auto rc = std::make_shared<RgbController>(core, cameraDeviceNum);
    auto ac = std::make_shared<ActuatorController>("/dev/tty.usbserial-A9S3VTXD");
    auto ns = std::make_shared<NetService>(core);

    sc->init();
    rc->init();
    ac->init();
    ns->init(port);

    boost::asio::deadline_timer timer(*core->getIOService());
    std::function<void(const boost::system::error_code&)> captureStuff;
    GyroReading gyroReading;
    ThermoReading thermoReading;
    captureStuff = [&](const boost::system::error_code& /*e*/) { 
        //
        cv::Vec2d pos = ac->getCurrentPosition();

        rc->captureFrame();
        auto rgbFrame = rc->popFrame();

        if(showRGB && rgbFrame->rows > 0) {
            rapidjson::Document doc;
            auto &aloc = doc.GetAllocator();
            doc.SetObject();

            cv::Mat imgMat(rgbFrame->rows, rgbFrame->cols, CV_8UC4, cv::Scalar::all(0.0));
            cv::cvtColor(*rgbFrame, imgMat, CV_BGR2RGBA, 4); 

            cv::Size size(rgbFrame->cols*0.2, rgbFrame->rows*0.2);
            cv::resize(imgMat, imgMat, size);

            std::string imgDataB64 = tobase64(imgMat.data, imgMat.total()*4*sizeof(byte));
            rapidjson::Value val;
            val.SetString(imgDataB64.c_str(), doc.GetAllocator());
            doc.AddMember("data", val, aloc);

            doc.AddMember("type", "rgb_data", aloc);
            doc.AddMember("yaw", -pos[0], aloc);
            doc.AddMember("pitch", -pos[1], aloc);
            doc.AddMember("dataWidth", imgMat.cols, aloc);
            doc.AddMember("dataHeight", imgMat.rows, aloc);
            doc.AddMember("yawSize", 63.625, aloc);
            doc.AddMember("pitchSize", 35.789, aloc);

            ns->sendWSDoc(doc);
        }


        /*if(sc->popGyroReading(gyroReading)) {
            printf("Roll: %f, Pitch: %f, Yaw: %f.\n",
                gyroReading.roll, gyroReading.pitch, gyroReading.yaw
            );
        }*/
        sc->requestThermoReading();

        std::cout << "tick: " << timer.expires_at() << std::endl;

        if(showThermal && sc->popThermoReading(thermoReading)){
            rapidjson::Document doc;
            auto &aloc = doc.GetAllocator();
            doc.SetObject();
            doc.AddMember("type", "thermo_data", aloc);
            doc.AddMember("yaw", -pos[0], aloc);
            doc.AddMember("pitch", -pos[1], aloc);

            cv::Mat imgMat(4, 16, CV_8UC4, cv::Scalar::all(0.0));
            cv::Mat mat = thermoReading.img;

            for(int i = 0; i < mat.total(); i++) {
                int y = 3-(i%4);
                int x = i/4;
                double temp = mat.at<float>(0, i);

                if(
                        (x == 11 && y == 2)
                    ||  (x == 11 && y == 3)
                    ||  (x == 12 && y == 2)
                ) {
                    temp += 10.0;
                }

                //std::cout << (int)temp << " ";

                cv::Vec4b col = hsv(
                    300-300.0*(std::max(temp, 14.0)-14.0)/(40.0-14.0),
                    1, 1
                );
                if(temp <= 11.0) {
                    col = cv::Vec4b(30, 30, 50, 255);
                } else if(temp > 40.0) {
                    col = cv::Vec4b(255, 255, 255, 255);
                }
                imgMat.at<cv::Vec4b>(y, x) = col;
                //std::cout << std::endl;
            }

            std::string imgDataB64 = tobase64(imgMat.data, imgMat.total()*4*sizeof(byte));
            rapidjson::Value val;
            val.SetString(imgDataB64.c_str(), doc.GetAllocator());
            doc.AddMember("data", val, aloc);

            ns->sendWSDoc(doc);
        }

        timer.expires_from_now(boost::posix_time::milliseconds(interval));
        timer.async_wait(captureStuff);
    };
    timer.expires_from_now(boost::posix_time::milliseconds(interval));
    timer.async_wait(captureStuff);

    ns->registerCallback("move_actuator", [&](const rapidjson::Document &doc) {
        ac->stop();
        ActuatorMoveOrder order;
        order.posDeg = cv::Vec2d(
            std::max(-150.0, std::min(150.0, -doc["yaw"  ].GetDouble()/M_PI*180)),
            std::max(- 90.0, std::min( 90.0, -doc["pitch"].GetDouble()/M_PI*180))
        );
        order.duration = 3.5;
        ac->queueMove(order);
    });
    
    std::cout << "run" << std::endl;
    core->run();
}