/* virtual */ void av::gua::NetTransform::_getStateFragment(const std::string& fragment, Msg& stateMsg) { // send an update message for the well-known group node of this fragment EIDGrpMap::iterator i = mGroupMap.find(fragment); if (i != mGroupMap.end()) { NetID group_id(fragment, NetID::sNetGroupRootNode); registerWellKnown(this, group_id); mGroupMap.insert(fragment); } stateMsg.setType(Msg::absolute); makeUpdateMessage(stateMsg, this); Link<SharedContainerHolder> container_holder; // send an update message for the well-known shared container node of this fragment SharedContainerMap::iterator container_iter = mSharedContainerMap.find(fragment); if (container_iter != mSharedContainerMap.end()) { container_holder = (*container_iter).second; } else { // a new node is needed container_holder = new SharedContainerHolder; container_holder->Name.setValue(fragment); NetID container_holder_id(fragment, NetID::sNetGroupContainerHolder); registerWellKnown(container_holder.getPtr(), container_holder_id); mSharedContainerMap[fragment] = container_holder; container_holder->registerNetTransform(this); sharedContainersChanged(); } stateMsg.setType(Msg::absolute); makeUpdateMessage(stateMsg, container_holder.getPtr()); }
// announce a newly distributed object void av::NetNode::notifyCreations() { #ifdef AVANGO_DEBUG logger.debug()<< "av::NetNode::notify_creations: " << "creations pending: " << mPendingCreations.size(); #endif if (!mPendingCreations.size()) { return; } typedef std::vector<DistributedSet::value_type> av_dst_vector; av_dst_vector tmp(mPendingCreations.begin(), mPendingCreations.end()); // erase the pending objects mPendingCreations.clear(); Msg p_msg; p_msg.setNetNode(this); int msg_count(0); av_dst_vector::reverse_iterator i; // follow it by an absolute update message to fill in the fields // because the creations go first, there is no possibility of dangling // references between newly created objects for (i=tmp.rbegin(); i!=tmp.rend(); ++i) { p_msg.setType(Msg::absolute); makeUpdateMessage(p_msg, *i); ++msg_count; } // send all of the creation messages to the rest of the group for (i=tmp.rbegin(); i!=tmp.rend(); ++i) { p_msg.setType(Msg::relative); makeCreateMessage(p_msg, *i); ++msg_count; } av_pushMsg(p_msg, msg_count); // p_msg << packed_msg; av_pushMsg(p_msg, sPackedMsg); #ifdef ZMQ_DISTRIBUTION_SUPPORT gServer->cast(p_msg); #else mMember->cast(p_msg); #endif }
void av::NetNode::getStateFragment(const std::string& fragment, av::Msg& stateOutMsg) { // a state has been requested. send it. Msg state_msg(stateOutMsg); state_msg.setNetNode(this); // request the current state std::vector<Link<Distributed> >::const_iterator i; std::vector<Link<Distributed> > state; mObjectMap.lookup(fragment, state); // pack into one message // let any client add something to the state _getStateFragment(fragment, state_msg); // then updates for the same objects state_msg.setType(Msg::absolute); for (i=state.begin(); i!=state.end(); ++i) { makeUpdateMessage(state_msg, *i); } av_pushMsg(state_msg, state.size()); // first the create messages for (i=state.begin(); i!=state.end(); ++i) { makeCreateMessage(state_msg, *i); } av_pushMsg(state_msg, state.size()); // ultra nasty hack stateOutMsg = state_msg.clone(); #ifdef AVANGO_DEBUG logger.debug()<< "av::NetNode::get_state_fragment: for " << fragment << " size: " << state_msg.getSize() << " bytes."; logger.debug()<< "av::NetNode::get_state_fragment: create messages: " << state.size(); logger.debug()<< "av::NetNode::get_state_fragment: update messages: " << state.size(); #endif }
// announce changes to registered distributed objects void av::NetNode::notifyUpdates() { #ifdef AVANGO_DEBUG logger.debug()<< "av::NetNode::notify_updates: " << "updates pending: " << mPendingUpdates.size(); #endif if (!mPendingUpdates.size()) return; typedef std::vector<DistributedSet::value_type> av_dst_vector; av_dst_vector tmp(mPendingUpdates.begin(), mPendingUpdates.end()); // erase the pending objects mPendingUpdates.clear(); Msg p_msg; p_msg.setNetNode(this); int msg_count(0); av_dst_vector::reverse_iterator i; for (i=tmp.rbegin(); i!=tmp.rend(); ++i) { p_msg.setType(Msg::relative); makeUpdateMessage(p_msg, *i); ++msg_count; } av_pushMsg(p_msg,msg_count); av_pushMsg(p_msg, sPackedMsg); #ifdef ZMQ_DISTRIBUTION_SUPPORT gServer->cast(p_msg); #else mMember->cast(p_msg); #endif }