bool MultiplexedSocket::CommitCallbacks(std::deque<StreamIDCallbackPair> ®istration, SocketConnectionPhase status, bool setConnectedStatus) { SerializationCheck::Scoped ss(this); bool statusChanged=false; if (setConnectedStatus||!mCallbackRegistration.empty()) { if (status==CONNECTED) { //do a little house cleaning and empty as many new requests as possible std::deque<RawRequest> newRequests; { boost::lock_guard<boost::mutex> connecting_mutex(sConnectingMutex); if (mNewRequests) { mNewRequests->popAll(&newRequests); delete mNewRequests; mNewRequests=NULL; } } for (std::deque<RawRequest>::iterator i=newRequests.begin(),ie=newRequests.end();i!=ie;++i) { sendBytesNow(getSharedPtr(),*i, true/*force since we promised to send them out*/); } } boost::lock_guard<boost::mutex> connecting_mutex(sConnectingMutex); statusChanged=(status!=mSocketConnectionPhase); if (setConnectedStatus) { if (status!=CONNECTED) { mSocketConnectionPhase=status; } else { mSocketConnectionPhase=WAITCONNECTING; std::deque<RawRequest> newRequests; { if (mNewRequests) { mNewRequests->popAll(&newRequests); delete mNewRequests; mNewRequests=NULL; } } for (std::deque<RawRequest>::iterator i=newRequests.begin(),ie=newRequests.end();i!=ie;++i) { sendBytesNow(getSharedPtr(),*i, true/*force since we promised to send them out*/); } delete mNewRequests; mNewRequests=NULL; mSocketConnectionPhase=CONNECTED; } } bool other_registrations=registration.empty(); mCallbackRegistration.swap(registration); } while (!registration.empty()) { ioReactorThreadCommitCallback(registration.front()); registration.pop_front(); } return statusChanged; }
void ProxyObject::setPhysics (const String& rhs, uint64 seqno, bool predictive) { if (seqno < mUpdateSeqno[LOC_PHYSICS_PART] && !predictive) return; if (!predictive) mUpdateSeqno[LOC_PHYSICS_PART] = seqno; mPhysics = rhs; ProxyObjectPtr ptr = getSharedPtr(); if (ptr) MeshProvider::notify ( &MeshListener::onSetPhysics, ptr, rhs); }
void ProxyObject::setOrientation(const TimedMotionQuaternion& reqorient, uint64 seqno) { PROXY_SERIALIZED(); if (SequencedPresenceProperties::setOrientation(reqorient, seqno)) { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); PositionProvider::notify(&PositionListener::updateLocation, ptr, mLoc, mOrientation, mBounds, mID); } }
//you can set a camera's mesh as of now. void ProxyObject::setMesh (Transfer::URI const& mesh, uint64 seqno) { PROXY_SERIALIZED(); if (SequencedPresenceProperties::setMesh(mesh, seqno)) { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); if (ptr) MeshProvider::notify ( &MeshListener::onSetMesh, ptr, mesh, mID); } }
void ProxyObject::setPhysics (const String& rhs, uint64 seqno) { PROXY_SERIALIZED(); if (SequencedPresenceProperties::setPhysics(rhs, seqno)) { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); if (ptr) MeshProvider::notify ( &MeshListener::onSetPhysics, ptr, rhs, mID); } }
void ProxyObject::setIsAggregate(bool isAggregate, uint64 seqno) { PROXY_SERIALIZED(); if (SequencedPresenceProperties::setIsAggregate(isAggregate, seqno)) { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); if (ptr) MeshProvider::notify ( &MeshListener::onSetIsAggregate, ptr, isAggregate, mID); } }
void MultiplexedSocket::connect(const Address&address, unsigned int numSockets, size_t max_enqueued_send_size, bool noDelay, unsigned int kernelSendBufferSize, unsigned int kernelReceiveBufferSize) { prepareConnect(numSockets,max_enqueued_send_size,noDelay,kernelSendBufferSize,kernelReceiveBufferSize); ASIOConnectAndHandshakePtr headerCheck(new ASIOConnectAndHandshake(getSharedPtr(), UUID::random())); //will notify connectionFailureOrSuccessCallback when resolved ASIOConnectAndHandshake::connect(headerCheck,address,noDelay); }
void ProxyObject::setBounds(const AggregateBoundingInfo& bnds, uint64 seqno) { PROXY_SERIALIZED(); if (SequencedPresenceProperties::setBounds(bnds, seqno)) { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); PositionProvider::notify(&PositionListener::updateLocation, ptr, mLoc, mOrientation, mBounds, mID); MeshProvider::notify (&MeshListener::onSetScale, ptr, mBounds.fullRadius(), mID); } }
void Charts::Chart::applyConstraints(void) { Transform transform = this->getTransform(); for(const auto & constraint : constraintList) { if(TR_VERIFY(constraint)) { transform = constraint->apply(getSharedPtr(), Utils::vec2ToSize(this->renderArgs.areaSize), transform); } } this->setTransform(transform); }
void ProxyObject::setBounds(const BoundingSphere3f& bnds, uint64 seqno, bool predictive) { if (seqno < mUpdateSeqno[LOC_BOUNDS_PART] && !predictive) return; if (!predictive) mUpdateSeqno[LOC_BOUNDS_PART] = seqno; mBounds = bnds; PositionProvider::notify(&PositionListener::updateLocation, mLoc, mOrientation, mBounds); ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); MeshProvider::notify (&MeshListener::onSetScale, ptr, mBounds.radius()); }
Simulation* HostedObject::runSimulation( const SpaceObjectReference& sporef, const String& simName, Network::IOStrandPtr simStrand) { if (stopped()) return NULL; PerPresenceData* pd = NULL; { Mutex::scoped_lock locker(presenceDataMutex); PresenceDataMap::iterator psd_it = mPresenceData.find(sporef); if (psd_it == mPresenceData.end()) { HO_LOG(error, "Error requesting to run a "<< \ "simulation for a presence that does not exist."); return NULL; } pd = psd_it->second; if (pd->sims.find(simName) != pd->sims.end()) { return pd->sims[simName]; } } Simulation* sim = NULL; // This is kept outside the lock because the constructor can // access the HostedObject and call methods which need the // lock. HO_LOG(info,String("[OH] Initializing ") + simName); try { sim = SimulationFactory::getSingleton().getConstructor ( simName ) ( mContext, static_cast<ConnectionEventProvider*>(mObjectHost), getSharedPtr(), sporef, getObjectHost()->getSimOptions(simName), simStrand ); } catch(FactoryMissingConstructorException exc) { sim = NULL; } if (!sim) { HO_LOG(error, "Unable to load " << simName << " plugin."); return NULL; } HO_LOG(info,String("Successfully initialized ") + simName); { Mutex::scoped_lock locker(presenceDataMutex); pd->sims[simName] = sim; sim->start(); } return sim; }
//you can set a camera's mesh as of now. void ProxyObject::setMesh (Transfer::URI const& mesh, uint64 seqno, bool predictive) { if (seqno < mUpdateSeqno[LOC_MESH_PART] && !predictive) return; if (!predictive) mUpdateSeqno[LOC_MESH_PART] = seqno; mMeshURI = mesh; ProxyObjectPtr ptr = getSharedPtr(); if (ptr) MeshProvider::notify ( &MeshListener::onSetMesh, ptr, mesh); }
bool HostedObject::objectHostConnect(const SpaceID spaceID, const Location startingLocation, const BoundingSphere3f meshBounds, const String mesh, const String physics, const String query, const String zernike, const ObjectReference orefID, PresenceToken token) { ObjectReference oref = (orefID == ObjectReference::null()) ? ObjectReference(UUID::random()) : orefID; SpaceObjectReference connectingSporef (spaceID,oref); // Note: we always use Time::null() here. The server will fill in the // appropriate value. When we get the callback, we can fix this up. Time approx_server_time = Time::null(); if (mObjectHost->connect( getSharedPtr(), connectingSporef, spaceID, TimedMotionVector3f(approx_server_time, MotionVector3f( Vector3f(startingLocation.getPosition()), startingLocation.getVelocity()) ), TimedMotionQuaternion(approx_server_time,MotionQuaternion(startingLocation.getOrientation().normal(),Quaternion(startingLocation.getAxisOfRotation(),startingLocation.getAngularSpeed()))), //normalize orientations meshBounds, mesh, physics, query, zernike, std::tr1::bind(&HostedObject::handleConnected, getWeakPtr(), mObjectHost, _1, _2, _3), std::tr1::bind(&HostedObject::handleMigrated, getWeakPtr(), _1, _2, _3), std::tr1::bind(&HostedObject::handleStreamCreated, getWeakPtr(), _1, _2, token), std::tr1::bind(&HostedObject::handleDisconnected, getWeakPtr(), _1, _2) )) { mObjectHost->registerHostedObject(connectingSporef,getSharedPtr()); return true; }else { return false; } }
void HostedObject::destroy(bool need_self) { // Avoid recursive destruction if (destroyed) return; if (mNumOutstandingConnections>0) { mDestroyWhenConnected=true; return;//don't destroy during delicate connection process } // Make sure that we survive the entire duration of this call. Otherwise all // references may be lost, resulting in the destructor getting called // (e.g. when the ObjectScript removes all references) and then we return // here to do more work and we've already been deleted. HostedObjectPtr self_ptr = need_self ? getSharedPtr() : HostedObjectPtr(); destroyed = true; if (mObjectScript) { // We need to clear out the reference in storage, which will also clear // out leases. mObjectHost->getStorage()->releaseBucket(id()); // Then clear out the script delete mObjectScript; mObjectScript=NULL; } //copying the data to a separate map before clearing to avoid deadlock in //destructor. PresenceDataMap toDeleteFrom; { Mutex::scoped_lock locker(presenceDataMutex); toDeleteFrom.swap(mPresenceData); } for (PresenceDataMap::iterator iter = toDeleteFrom.begin(); iter != toDeleteFrom.end(); ++iter) { // Make sure we explicitly. Other paths don't necessarily do this, // e.g. if the call to destroy happens between receiving a connection // success and the actual creation of the stream from the space, leaving // other components unaware that the connection has been made. Worst // case, the object host/session manager ignore the request. mObjectHost->disconnectObject(iter->first.space(),iter->first.object()); delete iter->second; // And just clear the ref out from the ObjectHost mObjectHost->unregisterHostedObject(iter->first,this); } }
void HostedObject::requestQueryUpdate(const SpaceID& space, const ObjectReference& oref, const String& new_query) { if (stopped()) { HO_LOG(detailed,"Ignoring query update request after system stop."); return; } SpaceObjectReference sporef(space,oref); Mutex::scoped_lock lock(presenceDataMutex); PresenceDataMap::iterator pdmIter = mPresenceData.find(sporef); if (pdmIter != mPresenceData.end()) { pdmIter->second->query = new_query; } else { SILOG(cppoh,error,"Error in cppoh, requesting solid angle update for presence that doesn't exist in your presence map."); } mObjectHost->getQueryProcessor()->updateQuery(getSharedPtr(), sporef, new_query); }
void FaceRecognitionFilterOpenCVImpl::process (cv::Mat &mat) { if (this->running && this->activeAlgorithms.size() > 0) { std::time_t frameTime = std::time(nullptr); int satisfiedThreshold = 0; // empty previous results results.clear(); this->p_face_training->get_face_recognition().predict( this->activeAlgorithms, mat, this->labels, this->confidences, this->targetWidth, this->targetHeight, this->minimumWidthFace, this->minimumHeightFace); for (size_t i = 0; i < this->activeAlgorithms.size(); i++) { OpenCVFaceRecognizer recognizer = this->activeAlgorithms[i]; const string& algorithm = FaceRecognition::OpenCVFaceRecognizerToString.at(recognizer); int label = this->labels[i]; double confidence = this->confidences[i]; double threshold = this->confidenceThresholdsMap[recognizer]; if (confidence >= 0.0 && confidence < threshold) { satisfiedThreshold++; } std::string labelString; std::ostringstream convert; convert << label; labelString = convert.str(); auto confidencePair = make_shared<AlgorithmConfidencePair>(AlgorithmConfidencePair(algorithm, confidence)); auto predictionResult = make_shared<AlgorithmPredictionResult>(AlgorithmPredictionResult(labelString, confidencePair)); results.push_back(predictionResult); } if (satisfiedThreshold > 0) { FaceDetected detected(getSharedPtr(), FaceDetected::getName(), results, (int) frameTime); // stop detecting once recognized this->running = false; signalFaceDetected(detected); } } }
ProxyObjectPtr HostedObject::createProxy(const SpaceObjectReference& objref, const SpaceObjectReference& owner_objref, const Transfer::URI& meshuri, TimedMotionVector3f& tmv, TimedMotionQuaternion& tmq, const BoundingSphere3f& bs, const String& phy, const String& query, bool isAggregate, uint64 seqNo) { ProxyManagerPtr proxy_manager = getProxyManager(owner_objref.space(), owner_objref.object()); Mutex::scoped_lock lock(presenceDataMutex); if (!proxy_manager) { mPresenceData.insert( PresenceDataMap::value_type( owner_objref, new PerPresenceData(getSharedPtr(), owner_objref.space(),owner_objref.object(), BaseDatagramLayerPtr(), query) ) ); proxy_manager = getProxyManager(owner_objref.space(), owner_objref.object()); } ProxyObjectPtr proxy_obj = proxy_manager->createObject(objref, tmv, tmq, bs, meshuri, phy, isAggregate, seqNo); return proxy_obj; }
void ProxyObject::destroy() { ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); ProxyObjectProvider::notify(&ProxyObjectListener::destroyed, ptr); }
void ProxyObject::invalidate(bool permanent) { mValid = false; ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); ProxyObjectProvider::notify(&ProxyObjectListener::invalidated, ptr, permanent); }
void ProxyObject::validate() { mValid = true; ProxyObjectPtr ptr = getSharedPtr(); assert(ptr); ProxyObjectProvider::notify(&ProxyObjectListener::validated, ptr); }
ProxyObjectPtr ProxyManager::createObject( const SpaceObjectReference& id, const TimedMotionVector3f& tmv, const TimedMotionQuaternion& tmq, const AggregateBoundingInfo& bs, const Transfer::URI& meshuri, const String& phy, bool isAggregate, uint64 seqNo ) { PROXYMAN_SERIALIZED(); ProxyObjectPtr newObj; // Try to reuse an existing object, even if we only have a valid // weak pointer to it. assert(id.space() == mID.space()); ProxyMap::iterator iter = mProxyMap.find(id.object()); if (iter != mProxyMap.end()) { // From strong ref newObj = iter->second.ptr; if (!newObj) { // From weak ref newObj = iter->second.wptr.lock(); // And either update the strong ref or clear out the entry // if its not even valid anymore. if (newObj) iter->second.ptr = newObj; else mProxyMap.erase(iter); } } // If we couldn't get a valid existing copy, create and insert a // new one. if (!newObj) { newObj = ProxyObject::construct(getSharedPtr(), id); std::pair<ProxyMap::iterator, bool> result = mProxyMap.insert( ProxyMap::value_type( newObj->getObjectReference().object(), ProxyData(newObj) ) ); iter = result.first; } assert(newObj); assert(newObj->getObjectReference() == id); assert(newObj->getOwner().get() == this); // This makes things simpler elsewhere: For new objects, we ensure // all the values are set properly so that when the notification // happens below, the proxy passed to listeners (for // onCreateProxy) will be completely setup, making it valid for // use. We don't need this for old ProxyObjects since they were // already initialized. The seqNo of 0 only updates something if it wasn't // set yet. newObj->setLocation(tmv, 0); newObj->setOrientation(tmq, 0); newObj->setBounds(bs, 0); if(meshuri) newObj->setMesh(meshuri, 0); if(phy.size() > 0) newObj->setPhysics(phy, 0); newObj->setIsAggregate(isAggregate, 0); // Notification of the proxy will have already occured, but // updates via, e.g., PositionListener or MeshListener, will go // out here, so the potentially invalid initial data automatically // filled when the object was created by createObject() shouldn't // matter. newObj->setLocation(tmv, seqNo); newObj->setOrientation(tmq, seqNo); newObj->setBounds(bs, seqNo); if(meshuri) newObj->setMesh(meshuri, seqNo); if(phy.size() > 0) newObj->setPhysics(phy, seqNo); newObj->setIsAggregate(isAggregate, seqNo); // Notification has to happen either way notify(&ProxyCreationListener::onCreateProxy, newObj); return newObj; }
Stream::ReceivedResponse MultiplexedSocket::receiveFullChunk(unsigned int whichSocket, Stream::StreamID id,Chunk&newChunk){ Stream::ReceivedResponse retval = Stream::AcceptedData; if (id==Stream::StreamID()) {//control packet if(newChunk.size()) { unsigned int controlCode=*newChunk.begin(); switch (controlCode) { case TCPStream::TCPStreamCloseStream: case TCPStream::TCPStreamAckCloseStream: if (newChunk.size()>1) { unsigned int avail_len=newChunk.size()-1; id.unserialize((const uint8*)&(newChunk[1]),avail_len); if (avail_len+1>newChunk.size()) { SILOG(tcpsst,warning,"Control Chunk too short"); } } if (id!=Stream::StreamID()) { std::tr1::unordered_map<Stream::StreamID,unsigned int>::iterator where=mAckedClosingStreams.find(id); if (where!=mAckedClosingStreams.end()){ where->second++; int how_much=where->second; if (where->second==mSockets.size()) { mAckedClosingStreams.erase(where); shutDownClosedStream(controlCode,id); if (controlCode==TCPStream::TCPStreamCloseStream) { closeStream(getSharedPtr(),id,TCPStream::TCPStreamAckCloseStream); } } }else{ if (mSockets.size()==1) { shutDownClosedStream(controlCode,id); if (controlCode==TCPStream::TCPStreamCloseStream) { closeStream(getSharedPtr(),id,TCPStream::TCPStreamAckCloseStream); } }else { mAckedClosingStreams[id]=1; } } } break; default: break; } } }else { std::deque<StreamIDCallbackPair> registrations; CommitCallbacks(registrations,CONNECTED,false); CallbackMap::iterator where=mCallbacks.find(id); if (where!=mCallbacks.end()) { retval=where->second->mBytesReceivedCallback(newChunk); }else if (mOneSidedClosingStreams.find(id)==mOneSidedClosingStreams.end()) { //new substream TCPStream*newStream=new TCPStream(getSharedPtr(),id); TCPSetCallbacks setCallbackFunctor(this,newStream); mNewSubstreamCallback(newStream,setCallbackFunctor); if (setCallbackFunctor.mCallbacks != NULL) { CommitCallbacks(registrations,CONNECTED,false);//make sure bytes are received retval=setCallbackFunctor.mCallbacks->mBytesReceivedCallback(newChunk); }else { closeStream(getSharedPtr(),id); } }else { //IGNORED MESSAGE } } return retval; }
ResourceLoadTask* GraphicsResourceShader::createLoadTask(DependencyManager *manager) { return new ShaderLoadTask(manager, getSharedPtr(), mResourceID.toString(), mArchiveName, mLoadEpoch); }
ResourceLoadTask* GraphicsResourceMesh::createLoadTask(DependencyManager *manager) { return new MeshLoadTask(manager, getSharedPtr(), mResourceID.toString(), mLoadEpoch); }