|
1 /* |
|
2 * Copyright (c) 2006 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: This header file describes the class that handles the storage |
|
15 * of triggers in RAM Structures. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "lbttriggeridgenerator.h" |
|
21 |
|
22 _LIT(KLbtTriggerIdFile,"lbttriggeridgenerator.dat"); |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // The Symbian 2 phase constructor |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CLbtTriggerIdGenerator* CLbtTriggerIdGenerator::NewL() |
|
31 { |
|
32 CLbtTriggerIdGenerator* self = new( ELeave ) CLbtTriggerIdGenerator; |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Destructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CLbtTriggerIdGenerator::~CLbtTriggerIdGenerator() |
|
45 { |
|
46 iFileHandle.Close(); |
|
47 iFileServer.Close(); |
|
48 } |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Constructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CLbtTriggerIdGenerator::CLbtTriggerIdGenerator() |
|
58 { |
|
59 // Nothing to do now |
|
60 } |
|
61 |
|
62 void CLbtTriggerIdGenerator::SetTriggerId(TInt64 aId) |
|
63 { |
|
64 HBufC8* trigId = NULL; |
|
65 TRAP_IGNORE(trigId=HBufC8::NewL(sizeof(TInt64))); |
|
66 TPtr8 ptr=trigId->Des(); |
|
67 ptr.AppendNum(aId); |
|
68 TInt pos = 0; |
|
69 iFileHandle.Seek(ESeekStart,pos); |
|
70 iFileHandle.Write(ptr); |
|
71 delete trigId; |
|
72 } |
|
73 |
|
74 TInt64 CLbtTriggerIdGenerator::GetTriggerId() |
|
75 { |
|
76 HBufC8* trigId = NULL; |
|
77 TRAP_IGNORE(trigId=HBufC8::NewL(sizeof(TInt64))); |
|
78 TPtr8 ptr=trigId->Des(); |
|
79 TInt pos = 0; |
|
80 iFileHandle.Seek(ESeekStart,pos); |
|
81 iFileHandle.Read(ptr); |
|
82 TLex8 lex(ptr); |
|
83 TInt64 iD; |
|
84 lex.Val(iD); |
|
85 delete trigId; |
|
86 return iD; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // The 2nd phase Symbian Constructor |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CLbtTriggerIdGenerator::ConstructL() |
|
94 { |
|
95 User::LeaveIfError(iFileServer.Connect()); |
|
96 // Obtain the file path |
|
97 TFileName trigIdFile; |
|
98 iFileServer.SessionPath(trigIdFile); |
|
99 |
|
100 // Create the Directory ie the private directory of the process |
|
101 iFileServer.MkDirAll(trigIdFile); |
|
102 |
|
103 // Generate the Db file |
|
104 trigIdFile.Append(KLbtTriggerIdFile); |
|
105 TInt createError=iFileHandle.Create(iFileServer,trigIdFile,EFileWrite); |
|
106 if(createError==KErrAlreadyExists) |
|
107 { |
|
108 createError=iFileHandle.Open(iFileServer,trigIdFile,EFileWrite); |
|
109 } |
|
110 else if(createError==KErrNone) |
|
111 { |
|
112 SetTriggerId(0); |
|
113 } |
|
114 User::LeaveIfError(createError); |
|
115 } |
|
116 |
|
117 // end of file |
|
118 |