void AutoNetServerImpl::HandleSubscribe(websocketpp::connection_hdl hdl) {
  m_Subscribers.insert(hdl);

  Json::array types;
  for(const auto& type : m_AllTypes) {
    types.push_back(type.first);
  }

  SendMessage(hdl, "subscribed", types);

  auto root = GetContext();
  for (auto ctxt : ContextEnumerator{ GetContext() }) {
    // Send update about this newly discovered context
    NewContext(
      ctxt == root ? nullptr : ctxt->GetParentContext().get(),
      *ctxt
    );

    // Build total image of all objects, recursively:
    for (const auto* pObj : ctxt->BuildObjectState())
      NewObject(*ctxt, *pObj);
  }

  // Send breakpoint message
  for(const auto& breakpoint : m_breakpoints)
    SendMessage(hdl, "breakpoint", breakpoint);
}
Пример #2
0
    Json JsonSerializer::Serialize(Colliders &colliders)
    {
        Json::array items;

        for (auto &collider : colliders)
            items.push_back(Serialize(collider));

        return Json(items);
    }
Пример #3
0
Json RiotService::GetMatchFeedByIds::internalCall() {
    Json summoners = _service->_api.getSummonerByIds(_params["ids"]);
    Json::object diff;
    Json::array matches;
    std::string err;
    auto cmp = [](const Json & a, const Json & b) {
        return a["createDate"].number_value() > b["createDate"].number_value();
    };
    for (auto & kv : summoners.object_items()) {
        Json cache = _service->getSummonerInfoCache(kv.first);
        printf("cache : %s\nnew: %s", cache.dump().c_str(), kv.second.dump().c_str());
        if (cache.is_null() || cache["revisionDate"].number_value() < kv.second["revisionDate"].number_value()) {
            diff[kv.first] = kv.second;
        } else {
            matches.insert(matches.end(), cache["games"].array_items().begin(), cache["games"].array_items().end());
        }
    }
    std::sort(matches.begin(), matches.end(), cmp);
    if (!matches.empty()) {
        _onRead(matches);
    }
    for (auto & kv : diff) {
        auto future = std::async(std::launch::async, [this, kv, cmp, &matches]() {
            Json newInfo = _service->_api.getRecentGamesBySummonerId(kv.first);
            if (!newInfo.is_null()) {
                Json::array modifiedMatches;
                for (auto & match : newInfo["games"].array_items()) {
                    auto item = match.object_items();
                    item["summonerId"] = kv.first;
                    item["name"] = kv.second["name"].string_value();
                    modifiedMatches.push_back(item);
                }
                matches.insert(matches.end(), modifiedMatches.begin(), modifiedMatches.end());
                sort(matches.begin(), matches.end(), cmp);
                
                Json::object updateObject(kv.second.object_items());
                updateObject["games"] = modifiedMatches;
                _service->saveSummonerInfo(kv.first, Json(updateObject));
            }
            _onRead(matches);
        });
    }
    return Json(matches);
}
void AutoNetServerImpl::SendEvent(const std::string& rawEvent, const std::vector<std::string>& args) {
  // Prepend '$' to custum event to avoid namespace collitions with internal events
  std::string event("$");
  event.append(rawEvent);

  Json::array jsonArgs;
  for (const auto& a : args) {
    jsonArgs.push_back(a);
  }

  *this += [this, event, jsonArgs] {
    for(auto hdl : m_Subscribers) {
      Json msg = Json::object{
        {"type", event},
        {"args", jsonArgs}
      };

      m_transport->Send(hdl, msg.dump());
    }
  };
}
Пример #5
0
                LOAD_PARAM(request, req, hint_R, number_value, NAN);
                string params_l1;
                LOAD_PARAM1(request, params_l1, params_l1, string_value, "");
                req.params_l1.decode(params_l1);

                Json::array results;
                auto it = request.object_items().find("urls");
                for (auto const &v: it->second.array_items()) {
                    req.url = v.string_value();
                    SearchResponse resp;
                    server->search(req, &resp);
                    Json::array hits;
                    for (auto const &hit: resp.hits) {
                        hits.push_back(Json::object{
                                {"key", hit.key},
                                {"meta", hit.meta},
                                {"details", hit.details},
                                {"score", hit.score}});
                    }
                    results.push_back(Json::object{
                    {"time", resp.time},
                    {"load_time", resp.load_time},
                    {"filter_time", resp.filter_time},
                    {"rank_time", resp.rank_time},
                    {"hits", hits}});
                }
                response = Json::object{{"results", results}};
          });
        add_json_api("/insert", "POST", [this](Json &response, Json &request) {
                authenticate(request);
                InsertRequest req;
void AutoNetServerImpl::NewObject(CoreContext& ctxt, const CoreObjectDescriptor& object){
  int contextID = ResolveContextID(&ctxt);

  *this += [this, object, contextID]{
    Json::object objData;
    Json::object types;

    // Add object data
    objData["name"] = autowiring::demangle(object.type);
    objData["id"] = autowiring::demangle(object.value.type());

    // Add slots for this object
    {
      Json::array slots;
      for(const SlotInformation* slot = object.stump->pHead; slot; slot = slot->pFlink) {
        slots.push_back(Json::object{
            {"id", autowiring::demangle(slot->type)},
            {"autoRequired", slot->autoRequired},
            {"offset", int(slot->slotOffset)}
        });
      }
      objData["slots"] = slots;
    }

    // Add type information
    auto member = object.pContextMember;
    if(member) {
      types["contextMember"] = true;
    }

    auto runnable = object.pCoreRunnable;
    if(runnable) {
      types["coreRunnable"] = true;
    }

    auto thread = object.pBasicThread;
    if(thread) {
      // Create slot in map
      m_Threads[thread->GetSelf<BasicThread>()];

      types["thread"] = Json::object{
          {"kernal", 0.0},
          {"user", 0.0}
      };
    }

    // Check if type implements an AutoFilter
    if (!object.subscriber.empty()) {
      Json::object args;
      for (auto pArg = object.subscriber.GetAutoFilterArguments(); *pArg; ++pArg) {
        args[autowiring::demangle(pArg->id)] = Json::object{
          {"id", autowiring::demangle(pArg->id)},
          {"isInput", pArg->is_input},
          {"isOutput", pArg->is_output}
        };
      }
      types["autoFilter"] = args;
    }

    auto filter = object.pFilter;
    if(filter) {
      types["exceptionFilter"] = true;
    }

    auto bolt = object.pBoltBase;
    if(bolt) {
      Json::array sigils;
      for(auto cur = bolt->GetContextSigils(); *cur; cur++){
        sigils.push_back(autowiring::demangle(*cur));
      }
      types["bolt"] = sigils;
    }

    BroadcastMessage("newObject", contextID, types, objData);
  };
}