SymbianSDKSensors.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * SymbianSDKSensors.cpp
  3. *
  4. * Created on: 22.12.2009
  5. * Author: Anssi
  6. */
  7. #define CRITERIA_ACCELEROMETERAXIS "AccelerometerAxis"
  8. #define CRITERIA_ACCELEROMETERDOUBLETAPPING "AccelerometerDoubleTapping"
  9. #define CRITERIA_ACCELEROMETERORIENTATION "Orientation"
  10. #define CRITERIA_ACCELEROMETERROTATION "Rotation"
  11. #define CRITERIA_ACCELEROMETERALL "All"
  12. #define ERR_CODE_OK 0 //Success
  13. #define ERR_CODE_INVALID_SERVICE_ARGUMENT 1000 //Invalid service argument
  14. #define ERR_CODE_UNKNOWN_ARGUMENT_NAME 1001 //Unknown argument name
  15. #define ERR_CODE_BAD_ARGUMENT_TYPE 1002 //Bad argument type
  16. #define ERR_CODE_MISSING_ARGUMENT 1003 //Missing argument
  17. #define ERR_CODE_SERVICE_NOT_SUPPORTED 1004 //Service not supported
  18. #define ERR_CODE_SERVICE_IN_USE 1005 //Service in use
  19. #define ERR_CODE_SERVICE_NOT_READY 1006 //Service not ready
  20. #define ERR_CODE_NO_MEMORY 1007 // No memory
  21. #define ERR_CODE_HARDWARE_NOT_AVAILABLE 1008 //Hardware not available
  22. #define ERR_CODE_SERVER_BUSY 1009 // Server busy
  23. #define ERR_CODE_ENTRY_EXISTS 1010 // Entry exists
  24. #define ERR_CODE_ACCEESS_DENIED 1011 // Access denied
  25. #define ERR_CODE_NOT_FOUND 1012 // Not found
  26. #define ERR_CODE_UNKNOWN_FORMAT 1013 // Unknown format
  27. #define ERR_CODE_GENERAL_ERROR 1014 // General error
  28. #define ERR_CODE_CANCEL_SUCCESS 1015 // Cancel success
  29. #define ERR_CODE_SERVICE_TIMED_OUT 1016 // Service timed-out
  30. #define ERR_CODE_PATH_NOT_FOUND 1017 // Path not found
  31. #include <QString>
  32. #include <QDebug>
  33. #include "SymbianSDKSensors.h"
  34. #include "sensordatalistener.h"
  35. #include <sensrvchannelfinder.h>
  36. #include <sensrvaccelerometersensor.h>
  37. #include <sensrvtappingsensor.h>
  38. #include <sensrvorientationsensor.h>
  39. #include <sensrvchannel.h>
  40. #include <e32base.h>
  41. SymbianSDKSensors::SymbianSDKSensors(Sensors &sensors) : m_sensors(sensors), m_transactionID(0x100)
  42. {
  43. // TODO Auto-generated constructor stub
  44. }
  45. SymbianSDKSensors::~SymbianSDKSensors()
  46. {
  47. // TODO Auto-generated destructor stub
  48. }
  49. void SymbianSDKSensors::findSensorChannel(const QString &criteria)
  50. {
  51. // criteria options: "All", "AccelerometerAxis", "AccelerometerDoubleTapping",
  52. // "Orientation", "Rotation"
  53. int ChannelId = 0,
  54. ContextType = 0,
  55. Quantity = 0,
  56. ChannelType = 0,
  57. DataItemSize = 0,
  58. ChannelDataTypeId = 0;
  59. //QString location("");
  60. //QString VendorId("");
  61. CSensrvChannelFinder* SensrvChannelFinder = CSensrvChannelFinder::NewLC();
  62. RSensrvChannelInfoList ChannelInfoList;
  63. CleanupClosePushL( ChannelInfoList );
  64. TSensrvChannelInfo mySearchConditions;
  65. // none, so matches all.
  66. SensrvChannelFinder->FindChannelsL(ChannelInfoList,mySearchConditions);
  67. // do something with the ChannelInfoList ChannelInfoList.Close();
  68. CleanupStack::Pop( &ChannelInfoList );
  69. CleanupStack::PopAndDestroy( SensrvChannelFinder );
  70. for ( TInt i = 0; i < ChannelInfoList.Count() ; i++ )
  71. {
  72. ChannelId = ChannelInfoList[i].iChannelId;
  73. ContextType = ChannelInfoList[i].iContextType;
  74. Quantity = ChannelInfoList[i].iQuantity;
  75. ChannelType = ChannelInfoList[i].iChannelType;
  76. DataItemSize = ChannelInfoList[i].iDataItemSize;
  77. ChannelDataTypeId = ChannelInfoList[i].iChannelDataTypeId;
  78. TBuf16<KSensrvLocationLength> Location16;
  79. TBuf16<KSensrvVendorIdLength> VendorId16;
  80. Location16.Copy(ChannelInfoList[i].iLocation);
  81. VendorId16.Copy(ChannelInfoList[i].iVendorId);
  82. QString location = QString((QChar*)(Location16.Ptr()), Location16.Length());//QString::fromRawData(reinterpret_cast<const QChar*>(ChannelInfoList[i].iLocation.Ptr()), ChannelInfoList[i].iLocation.Length());
  83. QString VendorId = QString((QChar*)(VendorId16.Ptr()), VendorId16.Length()); //QString::fromRawData(reinterpret_cast<const QChar*>(ChannelInfoList[i].iVendorId.Ptr()), ChannelInfoList[i].iVendorId.Length());
  84. if(criteria == CRITERIA_ACCELEROMETERAXIS && ChannelInfoList[i].iChannelType == KSensrvChannelTypeIdAccelerometerXYZAxisData)
  85. {
  86. // ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId
  87. m_sensors.addChannelInfo(ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId);
  88. }
  89. else if(criteria == CRITERIA_ACCELEROMETERDOUBLETAPPING && ChannelInfoList[i].iChannelType == KSensrvChannelTypeIdAccelerometerDoubleTappingData)
  90. {
  91. m_sensors.addChannelInfo(ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId);
  92. }
  93. else if(criteria == CRITERIA_ACCELEROMETERORIENTATION && ChannelInfoList[i].iChannelType == KSensrvChannelTypeIdOrientationData)
  94. {
  95. m_sensors.addChannelInfo(ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId);
  96. }
  97. else if(criteria == CRITERIA_ACCELEROMETERROTATION && ChannelInfoList[i].iChannelType == KSensrvChannelTypeIdRotationData)
  98. {
  99. m_sensors.addChannelInfo(ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId);
  100. }
  101. else if(criteria == CRITERIA_ACCELEROMETERALL)
  102. {
  103. m_sensors.addChannelInfo(ChannelId, ContextType, Quantity, ChannelType, location, VendorId, DataItemSize, ChannelDataTypeId);
  104. }
  105. }
  106. }
  107. int SymbianSDKSensors::registerForNotification(int ChannelId, int ContextType, int Quantity, int ChannelType, const QString &location, const QString &VendorId, int DataItemSize, int ChannelDataTypeId)
  108. {
  109. TSensrvChannelInfo info;
  110. info.iChannelId = ChannelId;
  111. info.iContextType = ContextType;
  112. info.iQuantity = Quantity;
  113. info.iChannelType = ChannelType;
  114. TPtrC locationDescriptor(static_cast<const TUint16*>(location.utf16()), location.length());
  115. info.iLocation.Append(locationDescriptor);
  116. TPtrC vendorIdDescriptor(static_cast<const TUint16*>(VendorId.utf16()), VendorId.length());
  117. info.iVendorId.Append(vendorIdDescriptor);
  118. info.iDataItemSize = DataItemSize;
  119. info.iChannelDataTypeId = ChannelDataTypeId;
  120. CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC();
  121. RSensrvChannelInfoList channelList;
  122. CleanupClosePushL(channelList);
  123. finder->FindChannelsL(channelList, info);
  124. if (channelList.Count() > 0)
  125. {
  126. m_transactionID++;
  127. info = channelList[0];
  128. CSensrvChannel *aChannel = CSensrvChannel::NewL(info);
  129. CSensorDataListener *listener = new CSensorDataListener(m_transactionID, m_sensors);
  130. aChannel->OpenChannelL();
  131. m_transactions.insert(m_transactionID, new TransactionObject(aChannel, listener));
  132. aChannel->StartDataListeningL(listener, 1, 1, 0);
  133. }
  134. channelList.Close();
  135. CleanupStack::Pop( &channelList );
  136. CleanupStack::PopAndDestroy( finder );
  137. return m_transactionID;
  138. }
  139. void SymbianSDKSensors::cancel(int criteria)
  140. {
  141. if(m_transactions.contains(criteria)) {
  142. TransactionObject *transactionToCancel = m_transactions[criteria];
  143. transactionToCancel->m_channel->StopDataListening();
  144. transactionToCancel->m_channel->CloseChannel();
  145. delete transactionToCancel;
  146. }
  147. }
  148. void SymbianSDKSensors::getChannelProperty(const QString &listeningType, int ChannelId, int ContextType, int Quantity, int ChannelType, const QString &location, const QString &VendorId, int DataItemSize, int ChannelDataTypeId, const QString &PropertyId)
  149. {
  150. TSensrvChannelInfo info;
  151. info.iChannelId = ChannelId;
  152. info.iContextType = ContextType;
  153. info.iQuantity = Quantity;
  154. info.iChannelType = ChannelType;
  155. TPtrC locationDescriptor(static_cast<const TUint16*>(location.utf16()), location.length());
  156. info.iLocation.Append(locationDescriptor);
  157. TPtrC vendorIdDescriptor(static_cast<const TUint16*>(VendorId.utf16()), VendorId.length());
  158. info.iVendorId.Append(vendorIdDescriptor);
  159. info.iDataItemSize = DataItemSize;
  160. info.iChannelDataTypeId = ChannelDataTypeId;
  161. CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC();
  162. RSensrvChannelInfoList channelList;
  163. CleanupClosePushL(channelList);
  164. finder->FindChannelsL(channelList, info);
  165. if (channelList.Count() > 0)
  166. {
  167. RSensrvPropertyList propertyList;
  168. info = channelList[0];
  169. CSensrvChannel *aChannel = CSensrvChannel::NewL(info);
  170. aChannel->GetAllPropertiesL(propertyList);
  171. delete aChannel;
  172. if(propertyList.Count() > 0)
  173. {
  174. //propertyList[0].GetPropertyId()
  175. QString PropertyId(QString::number(propertyList[0].GetPropertyId()));
  176. int PropertyDataType = propertyList[0].PropertyType();
  177. int ItemIndex = propertyList[0].GetArrayIndex();
  178. bool ReadOnly = propertyList[0].ReadOnly();
  179. //m_sensors.relayChannelProperties(PropertyId, PropertyDataType, ItemIndex, ReadOnly, PropertyValue);
  180. }
  181. }
  182. channelList.Close();
  183. CleanupStack::Pop( &channelList );
  184. CleanupStack::PopAndDestroy( finder );
  185. }