Exemplo n.º 1
0
      void
      getPlan(const IMC::PlanDB& req)
      {
        if (req.plan_id.empty())
        {
          onFailure(DTR("undefined plan id"));
          return;
        }

        *m_get_plan_stmt << req.plan_id;

        bool found = m_get_plan_stmt->execute();


        if (!found)
        {
          onFailure(DTR("undefined plan"));
        }
        else
        {
          Database::Blob data;
          *m_get_plan_stmt >> data;

          IMC::PlanSpecification* spec = new IMC::PlanSpecification;
          spec->deserializeFields((const uint8_t*)&data[0], data.size());
          m_reply.arg.set(spec);

          if (m_args.trace)
            spec->toText(std::cerr);

          onSuccess();
        }
        m_get_plan_stmt->reset();
      }
Exemplo n.º 2
0
      //! Look for a plan in the database
      //! @param[in] plan_id name of the plan
      //! @param[in] ps plan specification message
      //! @return true if plan is found
      bool
      lookForPlan(const std::string& plan_id, IMC::PlanSpecification& ps)
      {
        if (plan_id.empty())
        {
          onFailure(DTR("undefined plan id"));
          return false;
        }

        try
        {
          *m_get_plan_stmt << plan_id;

          if (!m_get_plan_stmt->execute())
          {
            onFailure(DTR("undefined plan"));
            m_get_plan_stmt->reset();
            return false;
          }

          Database::Blob data;

          *m_get_plan_stmt >> data;

          ps.deserializeFields((const uint8_t*)&data[0], data.size());

          m_get_plan_stmt->reset();
        }
        catch (std::runtime_error& e)
        {
          onFailure(DTR("failed loading from DB: %s"), e.what());
        }

        return true;
      }