1 /* |
|
2 * Copyright (c) 2005-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: M3GCore function call synchronization for J9 |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CSynchronization.h" |
|
20 |
|
21 NONSHARABLE_CLASS(M3gGlobals) |
|
22 { |
|
23 public: |
|
24 M3gGlobals() : mSync(0) {} |
|
25 |
|
26 public: |
|
27 CSynchronization* mSync; |
|
28 }; |
|
29 |
|
30 #if defined(__WINSCW__) |
|
31 |
|
32 #include <pls.h> |
|
33 M3gGlobals* getM3gGlobals() |
|
34 { |
|
35 // Access the PLS of this process. |
|
36 return Pls<M3gGlobals>(TUid::Uid(0x200211E2)); |
|
37 } |
|
38 |
|
39 #else |
|
40 |
|
41 static M3gGlobals* sGlobals = 0; |
|
42 |
|
43 M3gGlobals* getM3gGlobals() |
|
44 { |
|
45 if (sGlobals == 0) |
|
46 { |
|
47 sGlobals = new M3gGlobals(); |
|
48 } |
|
49 return sGlobals; |
|
50 } |
|
51 #endif |
|
52 |
|
53 |
|
54 // STATIC MEMBERS |
|
55 /*static*/ //CSynchronization* CSynchronization::iSelf = NULL; |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSynchronization::InstanceL |
|
59 // ----------------------------------------------------------------------------- |
|
60 /*static*/ CSynchronization* CSynchronization::InstanceL() |
|
61 { |
|
62 static M3gGlobals* globals = getM3gGlobals(); |
|
63 if (!globals->mSync) |
|
64 { |
|
65 globals->mSync = CSynchronization::NewL(); |
|
66 } |
|
67 return globals->mSync; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CSynchronization::NewL |
|
72 // ----------------------------------------------------------------------------- |
|
73 /*static*/ CSynchronization* CSynchronization::NewL() |
|
74 { |
|
75 CSynchronization* self = new(ELeave) CSynchronization(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSynchronization::ConstructL |
|
84 // ----------------------------------------------------------------------------- |
|
85 void CSynchronization::ConstructL() |
|
86 { |
|
87 User::LeaveIfError(iGuard.CreateLocal()); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSynchronization::CSynchronization |
|
92 // ----------------------------------------------------------------------------- |
|
93 CSynchronization::CSynchronization() : iErrorCode(0) |
|
94 { |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CSynchronization::~CSynchronization |
|
99 // ----------------------------------------------------------------------------- |
|
100 CSynchronization::~CSynchronization() |
|
101 { |
|
102 iGuard.Close(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CSynchronization::Lock |
|
107 // ----------------------------------------------------------------------------- |
|
108 void CSynchronization::Lock() |
|
109 { |
|
110 iGuard.Wait(); |
|
111 iErrorCode = 0; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CSynchronization::Unlock |
|
116 // ----------------------------------------------------------------------------- |
|
117 void CSynchronization::Unlock() |
|
118 { |
|
119 iErrorCode = 0; |
|
120 iGuard.Signal(); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CSynchronization::SetErrorCode |
|
125 // ----------------------------------------------------------------------------- |
|
126 void CSynchronization::SetErrorCode(TInt aCode) |
|
127 { |
|
128 iErrorCode = aCode; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CSynchronization::GetErrorCode |
|
133 // ----------------------------------------------------------------------------- |
|
134 TInt CSynchronization::GetErrorCode() |
|
135 { |
|
136 return iErrorCode; |
|
137 } |
|