Example #1
0
  /*
   * create a pipleline by giving a json configuration to FunfManger,
   * and get back the handle
   */
  private Pipeline getOrCreatePipeline() {
    // TODO Auto-generated method stub
    // try to get the pipeline, if not create a pipeline configuration here
    // <string name="mainPipelineConfig">{"@type":"edu.mit.dig.funftest.MainPipeline"}</string>
    // try
    parser = new JsonParser();
    Log.i(TAG, "Try to get pipeline from FunfMananger:" + mBoundFunfManager.toString());
    Pipeline pipeline = mBoundFunfManager.getRegisteredPipeline(pipelineName);

    if (gson == null) {
      gson = mBoundFunfManager.getGson();
    }

    if (pipeline == null) {
      Log.i(TAG, "We don't have the pipeline name:" + pipelineName + " ,try to create a new one");
      String pipeConfigStr =
          "{\"@type\":\"com.google.appinventor.components.runtime.SensorDBPipeline\"}";

      // add to funfManager by calling this new function, it will create Pipeline and register to
      // FunfManger

      mBoundFunfManager.createPipeline(pipelineName, pipeConfigStr);
      Log.i(TAG, "pipelineName:" + pipelineName);
      return mBoundFunfManager.getRegisteredPipeline(pipelineName);
    }

    return pipeline;
  }
Example #2
0
  @Override
  public void onDestroy() {

    for (JsonElement dataRequest : data) {
      manager.unrequestData(this, dataRequest);
    }
    for (Map.Entry<String, Schedule> schedule : schedules.entrySet()) {
      manager.unregisterPipelineAction(this, schedule.getKey());
    }
    if (uploader != null) {
      uploader.stop();
    }
    looper.quit();
    enabled = false;
  }
Example #3
0
  @SimpleFunction(description = "Discable export scheduled task")
  public void StopScheduleExport() {

    this.scheduleExportEnabled = false;
    mBoundFunfManager.unregisterPipelineAction(mPipeline, ACTION_EXPORT_DATA);
    mPipeline.setScheduleExportEnabled(false);
  }
Example #4
0
  @SimpleFunction(description = "Discable archive scheduled task")
  public void StopScheduleArchive() {

    this.scheduleArchiveEnabled = false;
    mBoundFunfManager.unregisterPipelineAction(mPipeline, ACTION_ARCHIVE_DATA);
    mPipeline.setScheduleArchiveEnabled(false);
  }
Example #5
0
  @SimpleFunction(description = "Remove data colleciton task of a specific sensor")
  public void RemoveSensorCollection(String sensorName) {
    if (mPipeline != null) {
      if (!sensorMapping.containsKey(sensorName)) {
        form.dispatchErrorOccurredEvent(
            SensorDB.this,
            "AddSensorCollection",
            ErrorMessages.ERROR_SENSORDB_NOTAVAILABLE,
            sensorName);
      }

      if (mPipeline.getActiveSensor().containsKey(sensorName)) {
        mPipeline.removeSensorCollection(sensorName);

        // if all sensor collection are removed, and if there are no more pipeline tasks in funf
        // then stop foreground
        if (!mBoundFunfManager.hasRegisteredJobs() && Launcher.isForeground()) {
          Log.i(TAG, "make funfManager stop foreground");
          Launcher.stopForeground(mainUIThreadActivity);
        }

      } else {
        // TODO: throw an exception saying the sensor is not active
        form.dispatchErrorOccurredEvent(
            SensorDB.this,
            "AddSensorCollection",
            ErrorMessages.ERROR_SENSORDB_NOTACTIVE,
            sensorName);
      }
    } else {
      Log.v(TAG, "Funf was killed by the system. In normal case, should not be here...");
    }
  }
Example #6
0
  @SimpleFunction(
      description = "Enable clear db backup schedule task with sepcified period in seconds")
  public void ScheduleClearBackup(int period) {
    this.scheduleClearbackupEnabled = true;
    this.clearbackup_period = period;

    Schedule clearbackupPeriod =
        new Schedule.BasicSchedule(
            BigDecimal.valueOf(this.clearbackup_period), BigDecimal.ZERO, false, false);
    mBoundFunfManager.registerPipelineAction(mPipeline, ACTION_CLEAR_BACKUP, clearbackupPeriod);

    mPipeline.setClearBackPeriod(period);
    mPipeline.setScheduleClearbackupEnabled(true);
  }
Example #7
0
  @Override
  public void onCreate(FunfManager manager) {

    if (archive == null) {
      archive = new DefaultArchive(manager, name);
    }
    if (uploader == null) {
      uploader = new UploadService(manager);
      uploader.start();
    }
    this.manager = manager;
    reloadDbHelper(manager);
    HandlerThread thread = new HandlerThread(getClass().getName());
    thread.start();
    this.looper = thread.getLooper();
    this.handler = new Handler(looper, callback);
    enabled = true;
    for (JsonElement dataRequest : data) {
      manager.requestData(this, dataRequest);
    }
    for (Map.Entry<String, Schedule> schedule : schedules.entrySet()) {
      manager.registerPipelineAction(this, schedule.getKey(), schedule.getValue());
    }
  }
Example #8
0
  @SimpleFunction(description = "Enable export db schedule task with specified period in seconds")
  public void ScheduleExport(int period) {

    this.scheduleExportEnabled = true;
    this.export_period = period;

    // register pipeline action with bound FunfManger
    Schedule exportPeriod =
        new Schedule.BasicSchedule(
            BigDecimal.valueOf(this.export_period), BigDecimal.ZERO, false, false);

    mBoundFunfManager.registerPipelineAction(mPipeline, ACTION_EXPORT_DATA, exportPeriod);
    mPipeline.setExportPeriod(period);
    mPipeline.setScheduleExportEnabled(true);
  }
Example #9
0
  /** @param period The time interval between each execution of the task */
  @SimpleFunction(description = "Enable archive schedule task with specified period in seconds")
  public void ScheduleArchive(int period) {

    this.scheduleArchiveEnabled = true;
    this.archive_period = period;

    // set Pipeline's variables for scheduleArchiveEnabled and archive_period as
    // well

    // register pipeline action with bound FunfManger

    Schedule archivePeriod =
        new Schedule.BasicSchedule(
            BigDecimal.valueOf(this.archive_period), BigDecimal.ZERO, false, false);
    // because we have the Pipeline handle, so we pass it to the FunfManager
    mBoundFunfManager.registerPipelineAction(mPipeline, ACTION_ARCHIVE_DATA, archivePeriod);

    mPipeline.setArchivePeriod(period);
    mPipeline.setScheduleArchiveEnabled(true);
  }
Example #10
0
 @SimpleFunction(description = "Disable clear backup task")
 public void StopClearDbBackup() {
   this.scheduleClearbackupEnabled = false;
   mBoundFunfManager.unregisterPipelineAction(mPipeline, ACTION_CLEAR_BACKUP);
   mPipeline.setScheduleClearbackupEnabled(false);
 }