当前位置: 首页>>代码示例>>C++>>正文


C++ shared_ptr::getContent方法代码示例

本文整理汇总了C++中ptr_lib::shared_ptr::getContent方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::getContent方法的具体用法?C++ shared_ptr::getContent怎么用?C++ shared_ptr::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ptr_lib::shared_ptr的用法示例。


在下文中一共展示了shared_ptr::getContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: timeout

void
Chat::onData
  (const ptr_lib::shared_ptr<const Interest>& interest,
   const ptr_lib::shared_ptr<Data>& data)
{
  SyncDemo::ChatMessage content;
  content.ParseFromArray(data->getContent().buf(), data->getContent().size());
  if (getNowMilliseconds() - content.timestamp() * 1000.0 < 120000.0) {
    string name = content.from();
    string prefix = data->getName().getPrefix(-2).toUri();
    int sessionNo = ::atoi(data->getName().get(-2).toEscapedString().c_str());
    int sequenceNo = ::atoi(data->getName().get(-1).toEscapedString().c_str());
    ostringstream tempStream;
    tempStream << name << sessionNo;
    string nameAndSession = tempStream.str();

    size_t l = 0;
    //update roster
    while (l < roster_.size()) {
      string tempName2 = roster_[l].substr(0, roster_[l].size() - 10);
      int tempSessionNo = ::atoi(roster_[l].substr(roster_[l].size() - 10, 10).c_str());
      if (name != tempName2 && content.type() != SyncDemo::ChatMessage_ChatMessageType_LEAVE)
        ++l;
      else {
        if (name == tempName2 && sessionNo > tempSessionNo)
          roster_[l] = nameAndSession;
        break;
      }
    }

    if (l == roster_.size()) {
      roster_.push_back(nameAndSession);
      cout << name << ": Join" << endl;
    }

    // Set the alive timeout using the Interest timeout mechanism.
    // TODO: Are we sure using a "/local/timeout" interest is the best future call approach?
    Interest timeout("/local/timeout");
    timeout.setInterestLifetimeMilliseconds(120000);
    face_.expressInterest
      (timeout, dummyOnData,
       bind(&Chat::alive, shared_from_this(), _1, sequenceNo, name, sessionNo, prefix));

    // isRecoverySyncState_ was set by sendInterest.
    // TODO: If isRecoverySyncState_ changed, this assumes that we won't get
    //   data from an interest sent before it changed.
    if (content.type() == SyncDemo::ChatMessage_ChatMessageType_CHAT &&
        !isRecoverySyncState_ && content.from() != screenName_)
      cout << content.from() << ": " << content.data() << endl;
    else if (content.type() == SyncDemo::ChatMessage_ChatMessageType_LEAVE) {
      // leave message
      int n = rosterFind(nameAndSession);
      if (n >= 0 && name != screenName_) {
        roster_.erase(roster_.begin() + n);
        cout << name << ": Leave" << endl;
      }
    }
  }
}
开发者ID:named-data,项目名称:ndn-cpp,代码行数:59,代码来源:test-chrono-chat.cpp

示例2: onData

 void onData(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& data)
 {
   ++callbackCount_;
   cout << "Got data packet with name " << data->getName().toUri() << endl;
   for (size_t i = 0; i < data->getContent().size(); ++i)
     cout << (*data->getContent())[i];
   cout << endl;
 }
开发者ID:named-data,项目名称:ndn-cpp,代码行数:8,代码来源:test-get-async.cpp

示例3:

void 
NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData)
{
  if (ndndIdData->getSignature().getType() == Signature::Sha256WithRsa)
    {
      ndndId_.resize(32);
      ndn_digestSha256(ndndIdData->getContent().value(), ndndIdData->getContent().value_size(), ndndId_.buf());
      onSuccess_();
    }
  else
    onFailure_();
}
开发者ID:ltr120,项目名称:ndn-cpp,代码行数:12,代码来源:ndnd-id-fetcher.hpp

示例4: registerRoute

/**
 * This is called when the face create command responds to decode the
 * encodedControlResonse as a TLV ControlResponse message containing one
 * ControlParameters. Get the face ID and call registerRoute().
 * @param expressedInterest The interest given to expressInterest.
 * @param responseData The response Data packet whose content is the
 * TLV-encoded ControlResponse.
 * @param prefix The prefix name to register.
 * @param face The Face which is used to sign the command interest and call
 * expressInterest.
 * @param enabled On success or error, set *enabled = false.
 */
static void
processCreateFaceResponse
  (const ptr_lib::shared_ptr<const Interest>& expressedInterest,
   const ptr_lib::shared_ptr<Data>& responseData, const Name& prefix, Face* face,
   bool* enabled)
{
  ndn_message::ControlParametersTypes_ControlParametersResponseMessage
    controlResponseMessage;
  ProtobufTlv::decode(controlResponseMessage, responseData->getContent());
  const ndn_message::ControlParametersTypes_ControlParametersResponse&
    controlResponse = controlResponseMessage.control_response();

  const int lowestErrorCode = 400;
  if (controlResponse.status_code() >= lowestErrorCode) {
    cout << "Face create command got error, code " <<
      controlResponse.status_code() << ": " + controlResponse.status_text() <<
      endl;
    *enabled = false;
    return;
  }
  if (controlResponse.control_parameters_size() != 1) {
    cout << "Face create command response does not have one ControlParameters" <<
      endl;
    *enabled = false;
    return;
  }

  boost::uint64_t faceId = controlResponse.control_parameters(0).face_id();

  cout << "Created face ID " << faceId << endl;
  registerRoute(prefix, faceId, face, enabled);
}
开发者ID:jiachenwang,项目名称:ndncon_Ubuntu_NDN_Hackathon2015,代码行数:44,代码来源:test-register-route.cpp

示例5:

void
Node::RegisterResponse::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& responseData)
{
  // Decode responseData->getContent() and check for a success code.
  // TODO: Move this into the TLV code.
  struct ndn_TlvDecoder decoder;
  ndn_TlvDecoder_initialize
    (&decoder, responseData->getContent().buf(),
     responseData->getContent().size());
  ndn_Error error;
  size_t endOffset;
  if ((error = ndn_TlvDecoder_readNestedTlvsStart
      (&decoder, ndn_Tlv_NfdCommand_ControlResponse, &endOffset))) {
    _LOG_DEBUG
      ("Register prefix failed: Error decoding the NFD response: " <<
       ndn_getErrorString(error));
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }
  uint64_t statusCode;
  if ((error = ndn_TlvDecoder_readNonNegativeIntegerTlv
       (&decoder, ndn_Tlv_NfdCommand_StatusCode, &statusCode))) {
    _LOG_DEBUG
      ("Register prefix failed: Error decoding the NFD response: " <<
       ndn_getErrorString(error));
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }

  // Status code 200 is "OK".
  if (statusCode != 200) {
    _LOG_DEBUG
      ("Register prefix failed: Expected NFD status code 200, got: " <<
       statusCode);
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }

  _LOG_DEBUG("Register prefix succeeded with the NFD forwarder for prefix " <<
             info_->prefix_->toUri());
}
开发者ID:susmit85,项目名称:ndn-cpp,代码行数:41,代码来源:node.cpp

示例6: ControlParameters

/**
 * This is called when the register route command responds to decode the
 * encodedControlResponse as a TLV ControlParametersResponse message
 * containing one ControlParameters. On success, print the ControlParameters
 * values which should be the same as requested.
 * @param expressedInterest The interest given to expressInterest.
 * @param responseData The response Data packet whose content is the TLV-encoded
 * ControlParametersResponse.
 * @param enabled On success or error, set *enabled = false.
 */
static void
processRegisterResponse
  (const ptr_lib::shared_ptr<const Interest>& expressedInterest,
   const ptr_lib::shared_ptr<Data>& responseData, bool* enabled)
{
  // We are finished in all cases.
  *enabled = false;

  ndn_message::ControlParametersTypes_ControlParametersResponseMessage
    decodedControlResponse;
  ProtobufTlv::decode(decodedControlResponse, responseData->getContent());
  const ndn_message::ControlParametersTypes_ControlParametersResponse&
    controlResponse = decodedControlResponse.control_response();

  const boost::uint64_t lowestErrorCode = 400;
  if (controlResponse.status_code() >= lowestErrorCode) {
    cout << "Face create command got error, code " <<
      controlResponse.status_code() <<": " + controlResponse.status_text();
    return;
  }
  if (controlResponse.control_parameters_size() != 1) {
    cout << "Face create command response does not have one ControlParameters";
    return;
  }

  // Success. Print the ControlParameters response.
  const ndn_message::ControlParametersTypes_ControlParameters& controlParameters =
    controlResponse.control_parameters(0);
  string name = "";
  for (size_t i = 0; i < controlParameters.name().component_size(); ++i)
    name += "/" + controlParameters.name().component(i);

  cout << "Successful in name registration: ControlParameters(Name: " << name <<
     ", FaceId: " << controlParameters.face_id() <<
     ", Origin: " << controlParameters.origin() <<
     ", Cost: " << controlParameters.cost() <<
     ", Flags: " << controlParameters.flags() << ")" << endl;
}
开发者ID:jiachenwang,项目名称:ndncon_Ubuntu_NDN_Hackathon2015,代码行数:48,代码来源:test-register-route.cpp


注:本文中的ptr_lib::shared_ptr::getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。