bluetoothengine/headsetsimulator/core/inc/RemoteControl/hsremotecontroltools.h
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/core/inc/RemoteControl/hsremotecontroltools.h	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,160 @@
+/*
+ * Component Name: Headset Simulator
+ * Author: Comarch S.A.
+ * Version: 1.0
+ * Copyright (c) 2010 Comarch S.A.
+ *  
+ * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on 
+ * the basis of the Member Contribution Agreement entered between Comarch S.A. 
+ * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be 
+ * used only in accordance with the terms and conditions of the Agreement. 
+ * Any other usage, duplication or redistribution of this Software is not 
+ * allowed without written permission of Comarch S.A.
+ * 
+ */
+
+#ifndef HSREMOTECONTROLTOOLS_H
+#define HSREMOTECONTROLTOOLS_H
+
+#include <e32base.h>
+
+#include "hsremoterequest.h"
+
+/** Request package length */
+const TInt KHsRemoteControlPackageLength = 128;
+
+/** Request package header length */
+const TInt KHsRemoteControlPackageTypeMaxLength = 2;
+
+_LIT8(KHsRemoteControllerPackageDelim, ":");
+
+/** Request package data */
+typedef TBuf8 <KHsRemoteControlPackageLength> THsControlCommandData;
+
+/**
+ * @brief Represents remote control request
+ */
+class THsRemoteControlCommand
+{
+public:
+    /**
+     * Constructor
+     * 
+     * @param aData data
+     * @param aCommandType type of command
+     */
+    THsRemoteControlCommand( THsControlCommandData& aData,
+            THsRemoteControlCommandType aCommandType );
+
+public:
+
+    /**
+     * Getter for type of command
+     * 
+     * @param aCmdType type  
+     */
+    void GetType( THsRemoteControlCommandType &aCmdType );
+
+    /**
+     * Getter for command's data
+     * 
+     * @param aCmdData data
+     * 
+     */
+    void GetData( TDes8 &aCmdData );
+
+    /**
+     * Clones THsRemoteControlCommand object
+     * 
+     * @param aCmdFrom source
+     * @param aCmdTo destination 
+     */
+    static void Copy( const THsRemoteControlCommand& aCmdFrom,
+            THsRemoteControlCommand& aCmdTo );
+private:
+
+    /** Data */
+    THsControlCommandData &iData;
+
+    /** Type */
+    THsRemoteControlCommandType iType;
+};
+
+/**
+ * @brief Parser for remote control packages
+ */
+class CHsRemoteControlParser : public CBase
+{
+public:
+    /**
+     * Two-phased constructor.
+     * 
+     * @return class instance
+     */
+    static CHsRemoteControlParser* NewL();
+
+    /**
+     * Two-phased constructor.
+     * 
+     * @return class instance
+     */
+    static CHsRemoteControlParser* NewLC();
+
+    /** 
+     * Destructor
+     */
+    ~CHsRemoteControlParser();
+
+public:
+    /**
+     * Parses and transforms data into THsRemoteControlCommand object
+     * 
+     * @param aText remote request package
+     * @param aCommand created command
+     */
+    void ParseL( const TDesC8 &aText, THsRemoteControlCommand &aCommand );
+
+private:
+    /**
+     * Constructor for performing 1st stage construction
+     */
+    CHsRemoteControlParser();
+
+    /**
+     * Constructor for performing 2nd stage construction
+     */
+    void ConstructL();
+
+private:
+
+    /**
+     * Checks if package is proper
+     * 
+     * @aData remote request package
+     * @return ETrue if OK, otherwise EFalse
+     */
+    TBool IsPackageValid( const TDesC8 &aData );
+
+    /**
+     * Retrieves header part and data part of remote request package
+     * 
+     * @param aData remote request package
+     * @param aTypePart header of the package
+     * @param aDataPart package's data
+     * @return error code value
+     */
+    TInt SplitPackage( const TDesC8 &aData, TDes8 &aTypePart, TDes8 &aDataPart );
+
+    /**
+     * Transforms header of the package into THsRemoteControlCommandType
+     *
+     * @param aTypePart header of the package
+     * @param aCommandType header tranformed into THsRemoteControlCommandType object
+     * @return error code value
+     */
+    TInt RecognizeType( const TDesC8 &aTypePart,
+            THsRemoteControlCommandType &aCommandType );
+
+};
+
+#endif // HSREMOTECONTROLTOOLS_H