genericopenlibs/openenvcore/libc/src/getpriority.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2005-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 // Name        : getpriority.cpp
       
    15 // Part of     : LIBC
       
    16 // Contains the source for fchdir
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21  
       
    22 #include <sys/time.h>
       
    23 #include <sys/resource.h>
       
    24 #include <errno.h>
       
    25 #include <e32std.h>
       
    26 #include <e32const.h>
       
    27 
       
    28 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
       
    29 #include "libc_wsd_defs.h"
       
    30 #endif
       
    31 
       
    32 #ifdef EMULATOR
       
    33 GET_GLOBAL_VAR_FROM_TLS(ProcPriority, int)
       
    34 #define ProcPriority (*GET_WSD_VAR_NAME(ProcPriority, g)())
       
    35 #else //EMULATOR
       
    36 int ProcPriority = 0;
       
    37 #endif //EMULATOR
       
    38 
       
    39 /*
       
    40 This function checks the range in which the priority of the process falls
       
    41 and returns the same to the function getpriority(). If the value is out of
       
    42 range it returns -1.
       
    43 */
       
    44 
       
    45 int convPri( TProcessPriority pri)
       
    46 	{
       
    47 	int priority;
       
    48 	
       
    49 	if(((pri == EPriorityLow ) &&
       
    50 		 ( (ProcPriority >= UPPER_LIMIT_PRIORITY_LOWEST) &&
       
    51 		 	 ( ProcPriority <= LOWER_LIMIT_PRIORITY_LOWEST) ))||
       
    52 		( pri == EPriorityBackground &&
       
    53 		 ( (ProcPriority >= UPPER_LIMIT_PRIORITY_BELOW_NORMAL) &&
       
    54 		 	 ( ProcPriority <= LOWER_LIMIT_PRIORITY_BELOW_NORMAL) )) ||
       
    55 		( pri == EPriorityForeground &&
       
    56 		 ( (ProcPriority >= UPPER_LIMIT_PRIORITY_NORMAL) &&
       
    57 		 	 ( ProcPriority <= LOWER_LIMIT_PRIORITY_NORMAL) )) ||
       
    58 		( pri == EPriorityHigh &&
       
    59 		 ( (ProcPriority >= UPPER_LIMIT_PRIORITY_ABOVE_NORMAL) &&
       
    60 		 	 ( ProcPriority <= LOWER_LIMIT_PRIORITY_ABOVE_NORMAL) ))||
       
    61 		( pri == EPriorityRealTimeServer &&
       
    62 		 ( (ProcPriority >= UPPER_LIMIT_PRIORITY_HIGHEST) &&
       
    63 		 	 ( ProcPriority <= LOWER_LIMIT_PRIORITY_HIGHEST) )))
       
    64 		{
       
    65 		priority = ProcPriority;
       
    66 		}
       
    67 	else
       
    68 		{
       
    69 		priority = -1;
       
    70 		errno = EINVAL;
       
    71 		}		
       
    72 	return priority;
       
    73 	}
       
    74 	
       
    75 /*
       
    76 This function checks if the which and who parameters sent are 
       
    77 'the process priority' and 'the current process' respectively,
       
    78 i.e. PROC_PROCESS and 0 respectively. And calls the function 
       
    79 convPri() to check in which range the priority falls and returns
       
    80 likewise.
       
    81 It returns a value in the range -20 to 19 on success and -1 is a 
       
    82 legitimate return value,so user has to check the errno to be sure 
       
    83 of failure.
       
    84 The function getpriority() shall ignore the values PRIO_PGRP,
       
    85 PRIO_USER as the argument 'which' and any other value other than
       
    86 0 for 'who' shall not be considered.
       
    87 */	
       
    88 
       
    89 extern "C" {
       
    90 
       
    91 EXPORT_C int getpriority(int which, int who)
       
    92 	{
       
    93 	int priority = -1;
       
    94 	if ( which == PRIO_PROCESS && who == 0 )
       
    95 		{
       
    96 		RProcess pro;
       
    97 		TProcessPriority pri;
       
    98 		pri = pro.Priority();		
       
    99 		priority = convPri( pri );
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		errno = ENOSYS;
       
   104 		}
       
   105 	return priority;
       
   106 	}
       
   107 
       
   108 } //extern "C"