javaextensions/sensor/src/sensorconnection.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Interface for Sensor
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef SENSORCONNECTION_H
       
    19 #define SENSORCONNECTION_H
       
    20 
       
    21 // EXTERNAL INCLUDES
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 #include "sensor.h"
       
    25 #include "sensorlistener.h"
       
    26 
       
    27 // DATA STRUCTURES
       
    28 struct DataFillerParams
       
    29 {
       
    30     DataFillerParams():
       
    31             iDatas(0),
       
    32             iIsDataLost(false),
       
    33             iDataCount(0),
       
    34             iDataObjects(0),
       
    35             iJavaPeer(0),
       
    36             iJniEnv(0)
       
    37     { };
       
    38     SensorData** iDatas;
       
    39     bool iIsDataLost;
       
    40     int iDataCount;
       
    41     void* iDataObjects;
       
    42     void* iJavaPeer;
       
    43     void* iJniEnv;
       
    44 };
       
    45 
       
    46 typedef void (*ConditionMetCB)(void*, void*, void*, int, double, long);
       
    47 typedef void (*DataReceivedCB)(DataFillerParams*);
       
    48 
       
    49 // CLASS DESCRIPTION
       
    50 /**
       
    51  * Interface for Sensor
       
    52  * Used for controlling sensors
       
    53  *
       
    54  * @lib N/A
       
    55  * @since S60 3.2
       
    56  */
       
    57 class SensorConnection : public SensorListener
       
    58 {
       
    59 public: // Constructor and Destructor
       
    60     /**
       
    61      * Destructor
       
    62      */
       
    63     ~SensorConnection();
       
    64 
       
    65     /**
       
    66      * Constructor
       
    67      * @param aSensor, Sensor assosiated with this connection
       
    68      */
       
    69     SensorConnection(Sensor* sensor);
       
    70 
       
    71 public: // From SensorListener
       
    72     void DataReceived(SensorData** aData, bool aIsDataLost);
       
    73 
       
    74     void ConditionMet(void* aHandle, int aChannelId,
       
    75                       double aValue, long aTimeStamp);
       
    76 
       
    77 public: // New methods
       
    78     /**
       
    79      * Returns pointer to actual sensor implementation
       
    80      */
       
    81     Sensor* GetSensor();
       
    82 
       
    83     /**
       
    84      * Returns assigned java peer object
       
    85      */
       
    86     void* GetJavaPeer()
       
    87     {
       
    88         return iJavaPeer;
       
    89     };
       
    90 
       
    91     /**
       
    92      * Sets java peer objet
       
    93      * @param aJavaPeer, peer object to set
       
    94      */
       
    95     void SetJavaPeer(void* aJavaPeer)
       
    96     {
       
    97         iJavaPeer = aJavaPeer;
       
    98     };
       
    99 
       
   100     /**
       
   101      * Store jni env
       
   102      */
       
   103     void SetJni(void* aJni)
       
   104     {
       
   105         iJniEnv = aJni;
       
   106     };
       
   107 
       
   108     /**
       
   109      * Sets callback methods
       
   110      * @param aDataReceived
       
   111      * @param aConditionMet
       
   112      */
       
   113     void SetCallbacks(DataReceivedCB aDataReceived,
       
   114                       ConditionMetCB aConditionMet)
       
   115     {
       
   116         iDataReceived = aDataReceived;
       
   117         iConditionMet = aConditionMet;
       
   118     }
       
   119     /**
       
   120      * Prepare for data listening
       
   121      * Creates sensor datas etc when needed
       
   122      * @return error code or 0 if no error
       
   123      */
       
   124     int PrepareDataListening(void* aNewDataObjects,
       
   125                              int aDataCount,
       
   126                              void*& aOldDataObject,
       
   127                              int aDataType);
       
   128 
       
   129     /**
       
   130      * Starts data listening
       
   131      */
       
   132     int StartDataListening(int aBufferSize,
       
   133                            long aBufferingPeriod,
       
   134                            bool aTimestampsIncluded,
       
   135                            bool aValiditiesIncluded,
       
   136                            bool aIsOneShot);
       
   137 
       
   138     /**
       
   139      * Returns stored dataobjects
       
   140      */
       
   141     void* DataObjects();
       
   142 
       
   143 private: // New methods
       
   144 
       
   145     // Allocates new data object
       
   146     SensorData** AllocateData(int aBufferSize,
       
   147                               int aDataType);
       
   148 
       
   149     // deletes data filler params and corresponding
       
   150     void ClearData(SensorData** aDatas, int aCount);
       
   151 
       
   152 private: // Data
       
   153     // Sensor, owned
       
   154     Sensor* iSensor;
       
   155 
       
   156     // Data filling parameters, owned
       
   157     DataFillerParams* iParams;
       
   158 
       
   159     // JNIEnv, not owned
       
   160     void* iJniEnv;
       
   161 
       
   162     // Java side peer object, not owned
       
   163     void* iJavaPeer;
       
   164 
       
   165     // Callback methods
       
   166     DataReceivedCB iDataReceived;
       
   167     ConditionMetCB iConditionMet;
       
   168 
       
   169     int iBufferSize;
       
   170     bool iTimeStamps;
       
   171     bool iValidities;
       
   172 };
       
   173 
       
   174 #endif // SENSORCONNECTION_H
       
   175 
       
   176 // End of file