|
1 // startup.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <fshell/common.mmh> |
|
15 #include <dscstore.h> |
|
16 #include <dscitem.h> |
|
17 |
|
18 using namespace IoUtils; |
|
19 |
|
20 class CCmdStartup : public CCommandBase |
|
21 { |
|
22 public: |
|
23 static CCommandBase* NewLC(); |
|
24 ~CCmdStartup(); |
|
25 private: |
|
26 CCmdStartup(); |
|
27 private: // From CCommandBase. |
|
28 virtual const TDesC& Name() const; |
|
29 virtual void DoRunL(); |
|
30 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
31 virtual void OptionsL(RCommandOptionList& aOptions); |
|
32 private: |
|
33 enum TOp |
|
34 { |
|
35 EList, |
|
36 EAdd, |
|
37 EDelete, |
|
38 }; |
|
39 TOp iOperation; |
|
40 TUid iDscUid; |
|
41 RDscStore iDsc; |
|
42 |
|
43 TUid iItemUid; |
|
44 HBufC* iItemFileName; |
|
45 HBufC* iItemArgs; |
|
46 TBool iCreate; |
|
47 }; |
|
48 |
|
49 EXE_BOILER_PLATE(CCmdStartup) |
|
50 |
|
51 CCommandBase* CCmdStartup::NewLC() |
|
52 { |
|
53 CCmdStartup* self = new(ELeave) CCmdStartup(); |
|
54 CleanupStack::PushL(self); |
|
55 self->BaseConstructL(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 CCmdStartup::~CCmdStartup() |
|
60 { |
|
61 iDsc.Close(); |
|
62 delete iItemFileName; |
|
63 delete iItemArgs; |
|
64 } |
|
65 |
|
66 CCmdStartup::CCmdStartup() |
|
67 : iDscUid(TUid::Uid(KDefaultSymbianDsc)) |
|
68 { |
|
69 } |
|
70 |
|
71 const TDesC& CCmdStartup::Name() const |
|
72 { |
|
73 _LIT(KName, "startup"); |
|
74 return KName; |
|
75 } |
|
76 |
|
77 void CCmdStartup::ArgumentsL(RCommandArgumentList& aArguments) |
|
78 { |
|
79 aArguments.AppendEnumL((TInt&)iOperation, _L("command")); |
|
80 aArguments.AppendStringL(iItemFileName, _L("filename")); |
|
81 aArguments.AppendStringL(iItemArgs, _L("arguments")); |
|
82 } |
|
83 |
|
84 void CCmdStartup::OptionsL(RCommandOptionList& aOptions) |
|
85 { |
|
86 aOptions.AppendUintL((TUint&)iDscUid.iUid, _L("dsc-uid")); |
|
87 aOptions.AppendBoolL(iCreate, _L("create")); |
|
88 } |
|
89 |
|
90 void EnumClose(TAny* aPtr) |
|
91 { |
|
92 static_cast<RDscStore*>(aPtr)->EnumClose(); |
|
93 } |
|
94 |
|
95 void CCmdStartup::DoRunL() |
|
96 { |
|
97 TRAPL(iDsc.OpenL(), _L("Couldn't open RDscStore")); |
|
98 |
|
99 if (iCreate && !iDsc.DscExistsL(iDscUid)) |
|
100 { |
|
101 TRAPL(iDsc.CreateDscL(iDscUid, _L("[DSC created by fshell_startup.exe]")), _L("Couldn't create DSC 0x%08x"), iDscUid.iUid); |
|
102 } |
|
103 |
|
104 if (iOperation == EList) |
|
105 { |
|
106 TRAPL(iDsc.EnumOpenLC(iDscUid); CleanupStack::Pop(), _L("Couldn't list DSC 0x%x"), iDscUid.iUid); |
|
107 CleanupStack::PushL(TCleanupItem(&EnumClose, &iDsc)); // Can't use the EnumOpenLC's cleanupitem because we have to pop it, because we need it inside its own TRAP harness to get good error messages out |
|
108 for (;;) |
|
109 { |
|
110 CDscItem* item = iDsc.EnumReadNextL(); |
|
111 if (!item) break; |
|
112 TPtrC args = item->Args(); |
|
113 TPtrC fn = item->FileName(); |
|
114 Printf(_L("DscId=0x%08x ItemId=0x%08x FileName=%S Args=%S\r\n"), item->DscId(), item->ItemId(), &fn, &args); |
|
115 delete item; |
|
116 } |
|
117 CleanupStack::PopAndDestroy(); // close enum |
|
118 } |
|
119 else if (iOperation == EAdd) |
|
120 { |
|
121 if (iItemFileName == NULL) LeaveIfErr(KErrArgument, _L("Must specify a file name for the 'add' operation")); |
|
122 CDscItem* item = CDscItem::NewLC(*iItemFileName, iItemArgs ? *iItemArgs : KNullDesC()); |
|
123 item->SetStartMethodL(EFireAndForget); |
|
124 item->SetStartupTypeL(EStartProcess); |
|
125 item->SetDscId(iDscUid); |
|
126 TRAPL(iDsc.AddItemL(*item), _L("Couldn't add DSC item (try using --create option?)")); |
|
127 CleanupStack::PopAndDestroy(item); |
|
128 } |
|
129 else if (iOperation == EDelete) |
|
130 { |
|
131 if (iItemFileName == NULL) LeaveIfErr(KErrArgument, _L("Must specify a file name for the 'delete' operation")); |
|
132 CDscItem* item = CDscItem::NewLC(*iItemFileName, iItemArgs ? *iItemArgs : KNullDesC()); |
|
133 item->SetDscId(iDscUid); |
|
134 TRAPL(iDsc.DeleteItemL(*item), _L("Couldn't delete DSC item")); |
|
135 CleanupStack::PopAndDestroy(item); |
|
136 } |
|
137 else |
|
138 { |
|
139 LeaveIfErr(KErrArgument, _L("Unrecognised operation %d"), iOperation); |
|
140 } |
|
141 } |