53
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// System includes
|
|
20 |
#include <swi/sisregistrysession.h>
|
|
21 |
#include <bautils.h>
|
|
22 |
//User Includes
|
|
23 |
#include "NotifyChange.h"
|
|
24 |
|
|
25 |
// Assuming that the path of registration resources will be @ c:\private\10003a3f\imports\apps
|
|
26 |
_LIT(KDirPath,":\\private\\10003a3f\\import\\apps\\");
|
|
27 |
// Wildcard to get only registration resources from above Path
|
|
28 |
_LIT(KWildName,"*_reg.rsc");
|
|
29 |
|
|
30 |
/*
|
|
31 |
*NewL- Wrapper funtion to invoke the constructor of CNotifyChange class.
|
|
32 |
*/
|
|
33 |
CNotifyChange* CNotifyChange::NewL(TChar aDriveLetter)
|
|
34 |
{
|
|
35 |
CNotifyChange* self=new (ELeave) CNotifyChange();
|
|
36 |
CleanupStack::PushL(self);
|
|
37 |
self->ConstructL(aDriveLetter);
|
|
38 |
CleanupStack::Pop(self);
|
|
39 |
return self;
|
|
40 |
}
|
|
41 |
|
|
42 |
/*
|
|
43 |
* Second Phase Constructor
|
|
44 |
*/
|
|
45 |
void CNotifyChange::ConstructL(TChar aDriveLetter) // second-phase constructor
|
|
46 |
{
|
|
47 |
User::LeaveIfError(iFs.Connect());
|
|
48 |
TBuf<KMaxFileName> aPath;
|
|
49 |
aPath.Append(aDriveLetter);
|
|
50 |
aPath.Append(KDirPath);
|
|
51 |
iPath = aPath.AllocL();
|
|
52 |
}
|
|
53 |
|
|
54 |
/*
|
|
55 |
* Constructor
|
|
56 |
*/
|
|
57 |
CNotifyChange::CNotifyChange():CActive(EPriorityStandard)
|
|
58 |
{
|
|
59 |
CActiveScheduler::Add(this);
|
|
60 |
}
|
|
61 |
|
|
62 |
/*
|
|
63 |
* StartFilesystemMonitor is used for issuing a Notify Change request to FileSystem for particular path
|
|
64 |
*/
|
|
65 |
void CNotifyChange::StartFilesystemMonitor()
|
|
66 |
{
|
|
67 |
TRequestStatus status;
|
|
68 |
iFs.NotifyChange(ENotifyWrite,status,*iPath);
|
|
69 |
SetActive();
|
|
70 |
RDebug::Print(_L("*********** Isuued Notify Change Request ************ "));
|
|
71 |
OstTrace0( TRACE_NORMAL, __STARTFILESYSTEMMONITOR, "AppRegExec::StartFilesystemMonitor - Isuued Notify Change Request");
|
|
72 |
}
|
|
73 |
|
|
74 |
/*
|
|
75 |
* RunL - Override function of CActive Class . will be invoked once FileSystem completes the request.
|
|
76 |
*/
|
|
77 |
void CNotifyChange::RunL()
|
|
78 |
{
|
|
79 |
TInt status = iStatus.Int();
|
|
80 |
if ( status == KErrCancel )
|
|
81 |
{
|
|
82 |
OstTrace1( TRACE_FATAL, __RUNL, "AppRegExec::RunL - Cancelled;status=%d",status);
|
|
83 |
return;
|
|
84 |
}
|
|
85 |
|
|
86 |
GetFilesFromDirL();
|
|
87 |
// Issue notify Request Again
|
|
88 |
StartFilesystemMonitor();
|
|
89 |
}
|
|
90 |
|
|
91 |
/*
|
|
92 |
* DoCancel - Override function of CAtive to Cancel any out standing request.
|
|
93 |
*/
|
|
94 |
void CNotifyChange::DoCancel()
|
|
95 |
{
|
|
96 |
// Cancel the outstanding file system request.
|
|
97 |
iFs.NotifyChangeCancel(iStatus);
|
|
98 |
}
|
|
99 |
|
|
100 |
/*
|
|
101 |
* RunError- Override function of CActive class will be used to handle the error if any occurs in RunL .
|
|
102 |
*/
|
|
103 |
TInt CNotifyChange::RunError(TInt aError)
|
|
104 |
{
|
|
105 |
OstTrace1( TRACE_FATAL, __RUNERROR, "AppRegExec::RunError;aError=%d",aError);
|
|
106 |
return (KErrNone); // Error has been handled.
|
|
107 |
}
|
|
108 |
|
|
109 |
/*
|
|
110 |
* Destructor
|
|
111 |
*/
|
|
112 |
CNotifyChange::~CNotifyChange()
|
|
113 |
{
|
|
114 |
Cancel();
|
|
115 |
if(iPath)
|
|
116 |
{
|
|
117 |
delete iPath;
|
|
118 |
}
|
|
119 |
iFs.Close();
|
|
120 |
}
|
|
121 |
|
|
122 |
/*
|
|
123 |
* GetFileFromDir- will be used to get the list of registration resources from a specified path.
|
|
124 |
*/
|
|
125 |
void CNotifyChange::GetFilesFromDirL()
|
|
126 |
{
|
|
127 |
iFs.SetSessionPath(iPath->Des());
|
|
128 |
CDir* fileList;
|
|
129 |
User::LeaveIfError(iFs.GetDir(KWildName,KEntryAttNormal,ESortByDate,fileList));
|
|
130 |
TInt count = fileList->Count();
|
|
131 |
if(count > 0)
|
|
132 |
{
|
|
133 |
TEntry entry = (*fileList)[count -1];
|
|
134 |
TPtrC filename = entry.iName;
|
|
135 |
TBuf<KMaxFileName> buf;
|
|
136 |
buf.Append(iPath->Des());
|
|
137 |
buf.Append(filename);
|
|
138 |
TBool ret = iFs.IsValidName(buf);
|
|
139 |
if(ret)
|
|
140 |
{
|
|
141 |
OstTrace0( TRACE_NORMAL, __GETFILESFROMDIR, "AppRegExec::GetFilesFromDir - Registrating Resources ...");
|
|
142 |
RegisterwithApparc(buf);
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
OstTrace1( TRACE_FATAL, __GETFILESFROMDIR_NOTVALID, "AppRegister::GetFilesFromDir - File doesn't Exist;ret=%d",ret);
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
/*
|
|
152 |
* RegisterwithApparc - will be used to register the resource with APPARC using SWI API's
|
|
153 |
*/
|
|
154 |
void CNotifyChange::RegisterwithApparc(TDesC& aFileName)
|
|
155 |
{
|
|
156 |
Swi::RSisRegistrySession rServer;
|
|
157 |
TInt ret = rServer.Connect();
|
|
158 |
OstTrace1( TRACE_FATAL, __REGISTERWITHAPPARC_CONNECTION, "AppRegExec::RegisterwithApparc - Connection status;ret=%d",ret);
|
|
159 |
CleanupClosePushL( rServer );
|
|
160 |
TRAP(ret, rServer.AddAppRegInfoL(aFileName));
|
|
161 |
RDebug::Print(aFileName);
|
|
162 |
OstTrace1( TRACE_FATAL, __REGISTERWITHAPPARC_REGITERED, "AppRegExec::RegisterwithApparc - Registered Resource;ret= %d",ret);
|
|
163 |
CleanupStack::PopAndDestroy(); //rServer*/
|
|
164 |
|
|
165 |
}
|
|
166 |
|