sysstatemgmt/systemstarter/dscstoresrc/dscitem.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <dscitem.h>
       
    17 #include <dscstoredefs.h>
       
    18 #include "dscdatabase.h"
       
    19 #include "sysstartpanic.h"
       
    20 
       
    21 
       
    22 /**
       
    23 Used to create an instance of the CDscItem class
       
    24 @return An instance of CDscItem
       
    25 @leave One of the system-wide error codes
       
    26 @publishedAll
       
    27 @released
       
    28 */
       
    29 EXPORT_C CDscItem* CDscItem::NewL()
       
    30 	{
       
    31 	CDscItem* self = CDscItem::NewLC();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;				
       
    34 	}
       
    35 
       
    36 /**
       
    37 Used to create an instance of the CDscItem class.
       
    38 The returned instance is put on the CleanupStack.
       
    39 @return An instance of CDscItem
       
    40 @leave One of the system-wide error codes
       
    41 @publishedAll
       
    42 @released
       
    43 */
       
    44 EXPORT_C CDscItem* CDscItem::NewLC()
       
    45 	{
       
    46 	CDscItem* self = new (ELeave) CDscItem();
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 /**
       
    53  @see NewL
       
    54  @see SetFileParamsL
       
    55  */
       
    56 EXPORT_C CDscItem* CDscItem::NewL(const TDesC& aFileName, const TDesC& aArgs)
       
    57 	{
       
    58 	CDscItem* self = CDscItem::NewLC(aFileName, aArgs);
       
    59 	CleanupStack::Pop(self);
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 /**
       
    64  @see NewLC
       
    65  @see SetFileParamsL
       
    66  */
       
    67 EXPORT_C CDscItem* CDscItem::NewLC(const TDesC& aFileName, const TDesC& aArgs)
       
    68 	{
       
    69 	CDscItem* self = CDscItem::NewLC();
       
    70 	self->SetFileParamsL(aFileName, aArgs);
       
    71 	return self;
       
    72 	}
       
    73 
       
    74 EXPORT_C CDscItem::~CDscItem()
       
    75 	{
       
    76 	delete iStartupProperties;
       
    77 	}
       
    78 
       
    79 CDscItem::CDscItem() :
       
    80 	iDscId(TUid::Uid(KDefaultSymbianDsc))
       
    81 	{
       
    82 	}
       
    83 	
       
    84 void CDscItem::ConstructL()
       
    85 	{
       
    86 	iStartupProperties = CStartupProperties::NewL();
       
    87 	}
       
    88 
       
    89 /** 
       
    90 Sets the Id of the Dynamic Startup Configuration list this item resides in. 
       
    91 The dscId of a DSC in the database must be set with this method before adding, updating, or deleting this item in this DSC
       
    92 @publishedAll
       
    93 @released
       
    94 @param aDscId Id of the DSC this item resides in.
       
    95 */
       
    96 EXPORT_C void CDscItem::SetDscId(const TUid& aDscId)
       
    97 	{
       
    98 	iDscId=aDscId;
       
    99 	}
       
   100 
       
   101 /** 
       
   102 Accessor function returning the DscId of the DSC this item was retrieved from
       
   103 @publishedAll
       
   104 @released
       
   105 @return DscId property
       
   106 */		
       
   107 EXPORT_C TUid CDscItem::DscId() const
       
   108 	{
       
   109 	return iDscId;
       
   110 	}
       
   111 	
       
   112 /** 
       
   113 Accessor function returning ItemId of the item
       
   114 @publishedAll
       
   115 @released
       
   116 @return ItemId property
       
   117 */	
       
   118 EXPORT_C TInt CDscItem::ItemId() const
       
   119 	{
       
   120 	return iItemId;
       
   121 	}
       
   122 	
       
   123 /**
       
   124 Accessor function returning the filename value of the item
       
   125 @publishedAll
       
   126 @released
       
   127 @return iStartupProperties->FileName
       
   128 @see CStartupProperties
       
   129 */
       
   130 EXPORT_C TPtrC CDscItem::FileName() const
       
   131 	{
       
   132 	return iStartupProperties->FileName();
       
   133 	}
       
   134 	
       
   135 /**
       
   136 Accessor function returning the args value of the item
       
   137 @publishedAll
       
   138 @released
       
   139 @return iStartupProperties->Args
       
   140 @see CStartupProperties
       
   141 */
       
   142 EXPORT_C TPtrC CDscItem::Args() const
       
   143 	{
       
   144 	return iStartupProperties->Args();
       
   145 	}
       
   146 
       
   147 /**
       
   148 Accessor function returning the startup type value of the item
       
   149 @publishedAll
       
   150 @released
       
   151 @return iStartupProperties->StartupType
       
   152 @see CStartupProperties
       
   153 */
       
   154 EXPORT_C TStartupType CDscItem::StartupType() const
       
   155 	{
       
   156 	return iStartupProperties->StartupType();
       
   157 	}
       
   158 	
       
   159 /**
       
   160 Accessor function returning the start method value of the item
       
   161 @publishedAll
       
   162 @released
       
   163 @return iStartupProperties->StartMethod
       
   164 @see CStartupProperties
       
   165 */
       
   166 EXPORT_C TStartMethod CDscItem::StartMethod() const
       
   167 	{
       
   168 	return iStartupProperties->StartMethod();
       
   169 	}
       
   170 	
       
   171 /**
       
   172 Accessor function returning the number of retries value of the item
       
   173 @publishedAll
       
   174 @released
       
   175 @return iStartupProperties->NoOfRetries
       
   176 @see CStartupProperties
       
   177 */
       
   178 EXPORT_C TInt CDscItem::NoOfRetries() const
       
   179 	{
       
   180 	return iStartupProperties->NoOfRetries();
       
   181 	}
       
   182 	
       
   183 /**
       
   184 Accessor function returning the timeout value of the item
       
   185 @publishedAll
       
   186 @released
       
   187 @return iStartupProperties->Timeout
       
   188 @see CStartupProperties
       
   189 */
       
   190 EXPORT_C TInt CDscItem::Timeout() const
       
   191 	{
       
   192 	return iStartupProperties->Timeout();
       
   193 	}
       
   194 
       
   195 /**
       
   196 Accessor function returning the monitored value of the item
       
   197 @publishedAll
       
   198 @released
       
   199 @return iStartupProperties->Monitored
       
   200 @see CStartupProperties
       
   201 */
       
   202 EXPORT_C TBool CDscItem::Monitored() const
       
   203 	{
       
   204 	return iStartupProperties->Monitored();
       
   205 	}
       
   206 
       
   207 /**
       
   208 Accessor function returning the viewless value of the item
       
   209 @publishedAll
       
   210 @released
       
   211 @return iStartupProperties->Viewless
       
   212 @see CStartupProperties
       
   213 */
       
   214 EXPORT_C TBool CDscItem::Viewless() const
       
   215 	{
       
   216 	return iStartupProperties->Viewless();
       
   217 	}
       
   218 
       
   219 /**
       
   220 Accessor function returning the StartInBackground value of the item
       
   221 @publishedAll
       
   222 @released
       
   223 @return iStartupProperties->StartInBackground
       
   224 @see CStartupProperties
       
   225 */
       
   226 EXPORT_C TBool CDscItem::StartInBackground() const
       
   227 	{
       
   228 	return iStartupProperties->StartInBackground();
       
   229 	}
       
   230 
       
   231 /**
       
   232 Sets the filename and args values of the item
       
   233 @publishedAll
       
   234 @released
       
   235 @param aFileName filename of the component. 
       
   236 @param aArgs arg list of the component. 
       
   237 @leave KErrArgument - the filename is empty or one of the parameters exceeds KDscStoreMaxStringLength
       
   238 @leave One of the system-wide error codes
       
   239 @see CStartupProperties
       
   240 */
       
   241 EXPORT_C void CDscItem::SetFileParamsL(const TDesC& aFileName, const TDesC& aArgs)
       
   242 	{
       
   243 	
       
   244 	if ((aFileName==KNullDesC) || (aFileName.Length() > CDscDatabase::MaxStringLength()) ||
       
   245 		(aArgs.Length() > CDscDatabase::MaxStringLength()))
       
   246 		{
       
   247 		User::Leave(KErrArgument);
       
   248 		}
       
   249 	iStartupProperties->SetFileParamsL(aFileName, aArgs);
       
   250 	}
       
   251 
       
   252 /**
       
   253 Sets the start method value of the item
       
   254 @publishedAll
       
   255 @released
       
   256 @param aStartMethod How we want to start the component
       
   257 @leave	KErrArgument - the start method is not either EFireAndForget or EWaitForStart
       
   258 @see CStartupProperties
       
   259 */
       
   260 EXPORT_C void CDscItem::SetStartMethodL(TStartMethod aStartMethod)
       
   261 	{
       
   262 	if ((aStartMethod != EFireAndForget) && (aStartMethod != EWaitForStart))
       
   263 		{
       
   264 		User::Leave(KErrArgument);
       
   265 		}
       
   266 	iStartupProperties->SetStartMethod(aStartMethod);
       
   267 	}
       
   268 
       
   269 /**
       
   270 Sets the number of retries value of the item
       
   271 @publishedAll
       
   272 @released
       
   273 @param aNumRetries number of retries should the start fail
       
   274 @leave	KErrArgument - the number of retries must be either 0 or 1
       
   275 @see CStartupProperties
       
   276 */
       
   277 EXPORT_C void CDscItem::SetNoOfRetriesL(TInt aNumRetries)
       
   278 	{
       
   279 	if (aNumRetries != 0 && aNumRetries != 1)
       
   280 		{
       
   281 		User::Leave(KErrArgument);
       
   282 		}
       
   283 	iStartupProperties->SetNoOfRetries(aNumRetries);
       
   284 	}
       
   285 	
       
   286 /**
       
   287 Sets the timeout value of the item
       
   288 @publishedAll
       
   289 @released
       
   290 @param aTimeout timeout between retries
       
   291 @leave	KErrArgument - the timeout must not be negative
       
   292 @see CStartupProperties
       
   293 */
       
   294 EXPORT_C void CDscItem::SetTimeoutL(TInt aTimeout)
       
   295 	{
       
   296 	if (aTimeout < 0)
       
   297 		{
       
   298 		User::Leave(KErrArgument);
       
   299 		}
       
   300 	iStartupProperties->SetTimeout(aTimeout);
       
   301 	}
       
   302 
       
   303 /**
       
   304 Sets the monitored value value of the item
       
   305 @publishedAll
       
   306 @released
       
   307 @param aMonitored Whether the component is to be monitored once it is started
       
   308 @see CStartupProperties
       
   309 */
       
   310 EXPORT_C void CDscItem::SetMonitored(TBool aMonitored)
       
   311 	{
       
   312 	iStartupProperties->SetMonitored(aMonitored);
       
   313 	}
       
   314 
       
   315 /**
       
   316 Sets the startup type value of the item
       
   317 @publishedAll
       
   318 @released
       
   319 @param aType The startup type
       
   320 @see CStartupProperties
       
   321 */
       
   322 EXPORT_C void CDscItem::SetStartupType(TStartupType aType)
       
   323 	{
       
   324 	iStartupProperties->SetStartupType(aType);
       
   325 	}
       
   326 
       
   327 /**
       
   328 Sets the viewless value of the item
       
   329 @publishedAll
       
   330 @released
       
   331 @param aViewless Whether the application is viewless or not
       
   332 @see CStartupProperties
       
   333 */
       
   334 EXPORT_C void CDscItem::SetViewless(TBool aViewless)
       
   335 	{
       
   336 	iStartupProperties->SetViewless(aViewless);
       
   337 	}
       
   338 
       
   339 /**
       
   340 Sets the StartInBackground value of the item
       
   341 @publishedAll
       
   342 @released
       
   343 @param aStartInBackground Whether to start the application in the background or not
       
   344 @see CStartupProperties
       
   345 */
       
   346 EXPORT_C void CDscItem::SetStartInBackground(TBool aStartInBackground)
       
   347 	{
       
   348 	iStartupProperties->SetStartInBackground(aStartInBackground);
       
   349 	}
       
   350 
       
   351 	
       
   352 /** 
       
   353 Returns a const reference to the embedded startup properties object
       
   354 @publishedAll
       
   355 @released
       
   356 @return Const reference to the embedded CStartupProperties object
       
   357 @see CStartupProperties
       
   358 */		
       
   359 EXPORT_C const CStartupProperties& CDscItem::StartupProperties() const
       
   360 	{
       
   361 		return (*iStartupProperties);
       
   362 	}
       
   363 
       
   364 /**
       
   365 Reset all variables in this instance back to constructor defaults. 
       
   366 This will enable to reuse this instance instead of having to delete it 
       
   367 and create a new one.
       
   368 @publishedAll
       
   369 @released
       
   370 */
       
   371 EXPORT_C void CDscItem::Reset()
       
   372 	{
       
   373 	iDscId = TUid::Uid(KDefaultSymbianDsc);
       
   374 	iItemId = 0;
       
   375 	iStartupProperties->Reset();
       
   376 	}
       
   377 
       
   378 /** 
       
   379 Sets itemId parameter for the item. Can only be set once.
       
   380 Normally the itemId is set by the DBMS, but if you know the itemId for a DscItem 
       
   381 in the database you can create an empty CDscItem, set the itemId+dscId and let the DBMS look 
       
   382 it up and fill in the other values.
       
   383 @internalComponent
       
   384 @released
       
   385 @param aItemId Id of the item. 
       
   386 @panic if you try to change the value
       
   387 */		
       
   388 EXPORT_C void CDscItem::SetItemId(const TInt aItemId)
       
   389 	{
       
   390 	if(aItemId != iItemId)
       
   391 		{
       
   392 		__ASSERT_ALWAYS( 0==iItemId, PanicNow(KPanicDsc, EIdCannotChange));
       
   393 		iItemId = aItemId;	
       
   394 		}
       
   395 	}
       
   396