/*
 * Test ToString()
 */
void DmxBufferTest::testToString() {
  DmxBuffer buffer;
  OLA_ASSERT_EQ(string(""), buffer.ToString());

  buffer.SetFromString("1,2,3,4");
  OLA_ASSERT_EQ(string("1,2,3,4"), buffer.ToString());

  buffer.SetRangeToValue(0, 255, 5);
  OLA_ASSERT_EQ(string("255,255,255,255,255"), buffer.ToString());
}
Example #2
0
void ShowPlayer::SendNextFrame() {
  DmxBuffer buffer;
  unsigned int universe;
  ShowLoader::State state = m_loader.NextFrame(&universe, &buffer);
  switch (state) {
    case ShowLoader::END_OF_FILE:
      HandleEndOfFile();
      return;
    case ShowLoader::INVALID_LINE:
      m_client.GetSelectServer()->Terminate();
      return;
    default:
      {}
  }

  state = RegisterNextTimeout();

  OLA_INFO << "Universe: " << universe << ": " << buffer.ToString();
  m_client.GetClient()->SendDmx(universe, buffer);

  switch (state) {
    case ShowLoader::END_OF_FILE:
      HandleEndOfFile();
      return;
    case ShowLoader::INVALID_LINE:
      m_client.GetSelectServer()->Terminate();
      return;
    default:
      {}
  }
}
/*
 * Callback for m_client.FetchDmx called by GetDmx
 * @param response the HTTPResponse
 * @param buffer the DmxBuffer
 * @param error Error message
 */
void OladHTTPServer::HandleGetDmx(HTTPResponse *response,
                                 const DmxBuffer &buffer,
                                 const string &error) {
  // rather than adding 512 JsonValue we cheat and use raw here
  stringstream str;
  str << "[" << buffer.ToString() << "]";
  JsonObject json;
  json.AddRaw("dmx", str.str());
  json.Add("error", error);

  response->SetNoCache();
  response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN);
  response->SendJson(json);
  delete response;
}
/*
 * Callback for m_client.FetchDmx called by GetDmx
 * @param response the HttpResponse
 * @param buffer the DmxBuffer
 * @param error Error message
 */
void OlaHttpServer::HandleGetDmx(HttpResponse *response,
                                 const DmxBuffer &buffer,
                                 const string &error) {
    stringstream str;
    str << "{" << endl;
    str << "  \"dmx\": [" << buffer.ToString() << "]," << endl;
    str << "  \"error\": \"" << error << "\"" << endl;
    str << "}";

    response->SetHeader("Cache-Control", "no-cache, must-revalidate");
    response->SetContentType(HttpServer::CONTENT_TYPE_PLAIN);
    response->Append(str.str());
    response->Send();
    delete response;
}
Example #5
0
void OladHTTPServer::HandleGetIntensity(HTTPResponse *response,
                                  const client::Result &result,
                                  const client::DMXMetadata &,
                                  const DmxBuffer &buffer) {
  // rather than adding 512 JsonValue we cheat and use raw here
  ostringstream str;
  str << "[" << buffer.ToString() << "]";
  JsonObject json;
  json.AddRaw("intensity", "50");
  json.Add("error", result.Error());

  response->SetNoCache();
  response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN);
  response->SendJson(json);
  delete response;
}