usbengines/usbotgwatcher/inc/cusbtimer.h
changeset 0 1e05558e2206
child 3 47c263f7e521
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usbengines/usbotgwatcher/inc/cusbtimer.h	Thu Dec 17 09:14:30 2009 +0200
@@ -0,0 +1,135 @@
+/*
+* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  timer
+ *
+*/
+
+#ifndef C_USBTIMER_H
+#define C_USBTIMER_H
+
+#include <e32base.h>
+
+class CUsbTimer;
+
+/**
+ * timer ids for usbotgwatcher
+ */
+enum TUsbTimerId
+    {
+    EDeviceAttachmentTimer,
+    EInactiveTimer,
+    EIconBlinkingTimer,
+    ETooMuchPowerRequiredTimer
+    };
+
+/**
+ * Observers gets feedback by implementing this interface
+ */
+class MUsbTimerObserver
+    {
+    friend class CtUsbOtgWatcher;
+
+public:
+
+    /**
+     * Observer must implement this interace
+     * which is called back when timer expires
+     * @param timer id
+     */
+    virtual void TimerElapsedL(TUsbTimerId aTimerId) = 0;
+    };
+
+/* *
+ * Wrapper class, will report to MUsbTimerObserver once time is over
+ * Name CUsbTimer is given due to CTimer name already used
+ */
+NONSHARABLE_CLASS(CUsbTimer) : public CActive
+    {
+public:
+
+    /**
+     * Two-phased constructor
+     *
+     * @param aObserver will get call back
+     * @param aTimerId timer id
+     */
+    static CUsbTimer * NewL(MUsbTimerObserver* aObserver,
+            TUsbTimerId aTimerId);
+
+    /**
+     * Destructor.
+     */
+    virtual ~CUsbTimer();
+
+    /**
+     * calls RunL after aMilliseconds
+     * @param aMilliseconds time in millisecs
+     */
+    void After(TInt aMilliseconds);
+
+public:
+
+    // from base class CActive
+    /**
+     * Called when request is completed
+     */
+    void RunL();
+
+    /**
+     * called when RunL leaves
+     * @param aError error code
+     * @return error code
+     */
+    TInt RunError(TInt aError);
+
+    /**
+     * Called when request is cancelled
+     */
+    void DoCancel();
+
+private:
+
+    /**
+     * Default constructor
+     * @param aObserver will get call back
+     * @param aTimerId timer id 
+     */
+    CUsbTimer(MUsbTimerObserver* aObserver, TUsbTimerId aTimerId);
+
+    /**
+     * 2nd phase construction
+     */
+    void ConstructL();
+
+private:
+    // data
+
+    /**
+     * Observer
+     * not own
+     */
+    MUsbTimerObserver* iObserver;
+
+    /**
+     * RTimer API
+     */
+    RTimer iTimer;
+
+    /**
+     * timer id
+     */
+    TUsbTimerId iTimerId;
+    };
+
+#endif //  C_USBTIMER_H