Ejemplo n.º 1
0
  @Override
  public void onDataReceived(IJsonObject probeConfig, IJsonObject data) {

    JsonObject record = new JsonObject();
    record.add("name", probeConfig.get(RuntimeTypeAdapterFactory.TYPE));
    record.add("value", data);
    handler.obtainMessage(DATA, record).sendToTarget();
  }
Ejemplo n.º 2
0
  protected void writeData(String name, IJsonObject data) {

    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    final double timestamp = data.get(ProbeKeys.BaseProbeKeys.TIMESTAMP).getAsDouble();
    final String value = data.toString();
    if (timestamp == 0L || name == null || value == null) {
      Log.e(
          LogUtil.TAG,
          "Unable to save data.  Not all required values specified. "
              + timestamp
              + " "
              + name
              + " - "
              + value);
      throw new SQLException("Not all required fields specified.");
    }

    String[] subStrings = name.split("\\.");
    String probeName = subStrings[subStrings.length - 1];

    ContentValues cv = new ContentValues();
    cv.put(DatabaseHelper.TABLE_STANDARD_PROBE, name);
    cv.put(DatabaseHelper.TABLE_STANDARD_VALUE, data.toString());
    cv.put(DatabaseHelper.TABLE_STANDARD_TIMESTAMP, TimeUtil.alignedTimestamp);
    for (String entry : data.getAllKeys())
      if (DatabaseHelper.getAllowedList().contains(entry.toLowerCase(Locale.ENGLISH))) {
        String toSave = data.toString();
        try {
          toSave = data.get(entry).getAsString();
        } catch (Exception e) {
          e.printStackTrace();
        }
        cv.put(entry, toSave);
      }

    db.insertOrThrow(probeName, "", cv);

    Log.e("Database", name + " " + TimeUtil.alignedTimestamp);

    Intent intent = new Intent("pipeline");
    intent.putExtra("Name", name);
    intent.putExtra("IJsonObject", data.toString());
    // intent.setAction("edu.mit.media.funf.pipeline.broadcastreceiver");
    LocalBroadcastManager.getInstance(getFunfManager()).sendBroadcast(intent);
    db.close();
  }