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