Beispiel #1
0
  @SimpleFunction(
      description =
          "Add sensor colleciton task for a specific sensor with"
              + " specified period (in seconds)")
  public void AddSensorCollection(String sensorName, int period) {
    // add to the list

    if (mPipeline != null) {
      // mapp the sensor to some probe's className
      if (sensorMapping.containsKey(sensorName)) {
        mPipeline.addSensorCollection(sensorName, period);

        // make the service on the foreground
        if (!Launcher.isForeground()) {
          Log.i(TAG, "make funfManager in the foreground....");
          Launcher.startForeground(mainUIThreadActivity);
        }

      } else {
        // TODO: throw an exception, saying the sensor does not exist, please
        // check the sensorMap
        form.dispatchErrorOccurredEvent(
            SensorDB.this,
            "AddSensorCollection",
            ErrorMessages.ERROR_SENSORDB_NOTAVAILABLE,
            sensorName);
      }
    } else {
      Log.v(TAG, "AddSensorCollection, pipeline is null, funf is killed by the system.");
    }
  }
Beispiel #2
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...");
    }
  }
Beispiel #3
0
  public SensorDB(ComponentContainer container) {
    super(container.$form());
    // TODO Auto-generated constructor stub
    // Set up listeners
    form.registerForOnDestroy(this);
    mainUIThreadActivity = container.$context();
    handler = new Handler();

    // we use dbName as pipelineName, each app (package) has their unique dbName, which is
    // packagename + "__SENSOR_DB__"
    pipelineName = SensorDbUtil.getPipelineName(mainUIThreadActivity);

    exportPath =
        new File(Environment.getExternalStorageDirectory(), form.getPackageName())
            + File.separator
            + "export";
    exportFormat =
        NameValueDatabaseService.EXPORT_CSV; // set the exporting format as csv by default

    //    Intent i = new Intent(mainUIThreadActivity, FunfManager.class);
    //    mainUIThreadActivity.startService(i);

    if (!Launcher.isLaunched()) {
      Log.i(TAG, "firstTime launching....");
      Launcher.launch(mainUIThreadActivity);
    }

    // bind to FunfManger (in case the user wants to set up the schedule)
    doBindService();
    // now we get(bind) to the Pipleline class that exists
    // we can set upload and archive periods using the pipeline
    form.registerForOnDestroy(this);
  }