|
1 /* |
|
2 * Copyright (c) 2008-2009 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 the License "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: |
|
15 * sts.h |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @publishedAll |
|
23 @released |
|
24 */ |
|
25 #include <usif/sts/sts.h> |
|
26 #include "stscommon.h" |
|
27 #include <e32cmn.h> |
|
28 #include <e32uid.h> |
|
29 |
|
30 using namespace Usif; |
|
31 |
|
32 |
|
33 void RStsSession::ConnectL() |
|
34 { |
|
35 __ASSERT_DEBUG(iHandle == NULL, User::Invariant()); |
|
36 TInt err = RScsClientBase::Connect(KStsServerName, TVersion(KStsVerMajor, |
|
37 KStsVerMinor, KStsVerBuild), KStsServerImgName, TUidType( |
|
38 KExecutableImageUid, KNullUid, TUid::Uid(KUidStsServer))); |
|
39 User::LeaveIfError(err); |
|
40 } |
|
41 |
|
42 EXPORT_C RStsSession::RStsSession() |
|
43 : RScsClientBase() |
|
44 { |
|
45 // empty |
|
46 } |
|
47 |
|
48 EXPORT_C void RStsSession::Close() |
|
49 { |
|
50 RScsClientBase::Close(); |
|
51 } |
|
52 |
|
53 EXPORT_C TStsTransactionId RStsSession::CreateTransactionL() |
|
54 { |
|
55 // It is possible to create several transactions on the same session, assuming that they are all sequential |
|
56 if (iHandle == NULL) |
|
57 ConnectL(); |
|
58 TStsTransactionId trID; |
|
59 TPckg<TStsTransactionId> idPkg(trID); |
|
60 TIpcArgs ipcArgs; |
|
61 ipcArgs.Set(KIdIPCSlot, &idPkg); |
|
62 User::LeaveIfError(CallSessionFunction(ECreateTransaction, ipcArgs)); |
|
63 return trID; |
|
64 } |
|
65 |
|
66 EXPORT_C void RStsSession::OpenTransactionL(TStsTransactionId aTransactionID) |
|
67 { |
|
68 if (iHandle == NULL) |
|
69 ConnectL(); |
|
70 TPckgC<TStsTransactionId> idPkg(aTransactionID); |
|
71 TIpcArgs ipcArgs; |
|
72 ipcArgs.Set(KIdIPCSlot, &idPkg); |
|
73 User::LeaveIfError(CallSessionFunction(EOpenTransaction, ipcArgs)); |
|
74 } |
|
75 |
|
76 EXPORT_C void RStsSession::RegisterNewL(const TDesC& aFileName) |
|
77 { |
|
78 TIpcArgs ipcArgs; |
|
79 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
80 User::LeaveIfError(CallSessionFunction(ERegisterNew, ipcArgs)); |
|
81 } |
|
82 |
|
83 EXPORT_C void RStsSession::CreateNewL(const TDesC& aFileName, RFile &aFile, TUint aCreateMode) |
|
84 { |
|
85 __ASSERT_DEBUG(((KFilePathIPCSlot!=KFileHandleIPCSlot) && |
|
86 (KFilePathIPCSlot!=KFileModeIPCSlot) && |
|
87 (KFileModeIPCSlot!=KFileHandleIPCSlot)), User::Invariant()); |
|
88 |
|
89 TPckgBuf<TInt> fileHandlePkg; |
|
90 TPckgC<TUint> pkgFileMode(aCreateMode); |
|
91 TIpcArgs ipcArgs; |
|
92 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
93 ipcArgs.Set(KFileHandleIPCSlot, &fileHandlePkg); |
|
94 ipcArgs.Set(KFileModeIPCSlot, &pkgFileMode); |
|
95 TInt fileServerHandle = User::LeaveIfError(CallSessionFunction(ECreateNew, ipcArgs)); |
|
96 User::LeaveIfError(aFile.AdoptFromServer(fileServerHandle, fileHandlePkg())); |
|
97 } |
|
98 |
|
99 EXPORT_C void RStsSession::RemoveL(const TDesC& aFileName) |
|
100 { |
|
101 TIpcArgs ipcArgs; |
|
102 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
103 User::LeaveIfError(CallSessionFunction(ERemove, ipcArgs)); |
|
104 } |
|
105 |
|
106 EXPORT_C void RStsSession::RegisterTemporaryL(const TDesC& aFileName) |
|
107 { |
|
108 TIpcArgs ipcArgs; |
|
109 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
110 User::LeaveIfError(CallSessionFunction(ERegisterTemporary, ipcArgs)); |
|
111 } |
|
112 |
|
113 EXPORT_C void RStsSession::CreateTemporaryL(const TDesC& aFileName, RFile &aFile, TUint aCreateMode) |
|
114 { |
|
115 __ASSERT_DEBUG(((KFilePathIPCSlot!=KFileHandleIPCSlot) && |
|
116 (KFilePathIPCSlot!=KFileModeIPCSlot) && |
|
117 (KFileModeIPCSlot!=KFileHandleIPCSlot)), User::Invariant()); |
|
118 |
|
119 TPckgBuf<TInt> fileHandlePkg; |
|
120 TPckgC<TUint> pkgFileMode(aCreateMode); |
|
121 TIpcArgs ipcArgs; |
|
122 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
123 ipcArgs.Set(KFileHandleIPCSlot, &fileHandlePkg); |
|
124 ipcArgs.Set(KFileModeIPCSlot, &pkgFileMode); |
|
125 TInt fileServerHandle = User::LeaveIfError(CallSessionFunction(ECreateTemporary, ipcArgs)); |
|
126 User::LeaveIfError(aFile.AdoptFromServer(fileServerHandle, fileHandlePkg())); |
|
127 } |
|
128 |
|
129 EXPORT_C void RStsSession::OverwriteL(const TDesC& aFileName, RFile &aFile, TUint aCreateMode) |
|
130 { |
|
131 __ASSERT_DEBUG(((KFilePathIPCSlot!=KFileHandleIPCSlot) && |
|
132 (KFilePathIPCSlot!=KFileModeIPCSlot) && |
|
133 (KFileModeIPCSlot!=KFileHandleIPCSlot)), User::Invariant()); |
|
134 |
|
135 TPckgBuf<TInt> fileHandlePkg; |
|
136 TPckgC<TUint> pkgFileMode(aCreateMode); |
|
137 TIpcArgs ipcArgs; |
|
138 ipcArgs.Set(KFilePathIPCSlot, &aFileName); |
|
139 ipcArgs.Set(KFileHandleIPCSlot, &fileHandlePkg); |
|
140 ipcArgs.Set(KFileModeIPCSlot, &pkgFileMode); |
|
141 TInt fileServerHandle = User::LeaveIfError(CallSessionFunction(EOverwrite, ipcArgs)); |
|
142 User::LeaveIfError(aFile.AdoptFromServer(fileServerHandle, fileHandlePkg())); |
|
143 } |
|
144 |
|
145 EXPORT_C void RStsSession::CommitL() |
|
146 { |
|
147 User::LeaveIfError(CallSessionFunction(ECommit)); |
|
148 Close(); |
|
149 } |
|
150 |
|
151 EXPORT_C void RStsSession::RollBackL() |
|
152 { |
|
153 User::LeaveIfError(CallSessionFunction(ERollBack)); |
|
154 Close(); |
|
155 } |
|
156 |
|
157 EXPORT_C TStsTransactionId RStsSession::TransactionIdL() |
|
158 { |
|
159 TStsTransactionId id; |
|
160 TPckg<TStsTransactionId> idPkg(id); |
|
161 TIpcArgs ipcArgs; |
|
162 ipcArgs.Set(KIdIPCSlot, &idPkg); |
|
163 User::LeaveIfError(CallSessionFunction(EGetId, ipcArgs)); |
|
164 return id; |
|
165 } |
|
166 |