First public contribution.
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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <e32def_private.h>
25 EXPORT_C TInt RPipe::Init()
27 Static method to load the pipe device driver.
31 @return KErrNone If the pipe is successfully loaded, otherwise one of the
32 system wide error code.
35 _LIT(KDriverLddFileName,"PIPELIB");
36 return User::LoadLogicalDevice(KDriverLddFileName);
40 EXPORT_C TInt RPipe::Create( TInt aSize, RPipe& aReader, RPipe& aWriter, TOwnerType aTypeR, TOwnerType aTypeW)
42 Static method to create a new, unnamed pipe.
43 By default, any thread in the process can use the handle to access the Pipe. However,
44 specifying EOwnerThread as the second and fourth parameter to this function, means
45 that only the creating thread can use this handle to access the Pipe.
47 @param aReader Handle to the read end of the pipe. If the call is successful,
48 this handle will be opened for reading.
49 @param aWriter Handle to the write end of the pipe. If the call is successful,
50 this handle will be opened for writing.
51 @param aTypeR, aTypeW The type of the ownership of the handle to be created for the
53 @param aSize Size of the pipe to be created, in bytes.
55 @return KErrNone Pipe successfully created and the read and write handles opened,
56 KErrOverflow Maximum number of pipes has been reached.
57 KErrNoMemory Insufficient memory to create pipe
58 KErrArgument If the specified size is negative or zero
59 KErrInUse The current handle has already been opened.
60 otherwise one of the other system wide error codes
64 TInt err = aReader.Create(aSize, aTypeR);
69 err = aWriter.Open(aReader, aTypeW);
76 TInt RPipe::Create(TInt aSize, TOwnerType aType)
78 Creates a Kernel side pipe and opens a handle for reading.
79 By default any thread in the process can use the handle to access to Read the Pipe.
80 However, specifying EOwnerThread as the second parameter to this function, means
81 that only the creating thread can use this handle to access the pipe.
83 @param aSize Size of the pipe to create, in bytes.
85 @param aType The type of the handle to be created for the reading
88 @return KErrNone Pipe successfully created and handle opened for reading,
89 KErrInUse The current handle has already been opened.
90 KErrOverflow Maximum number of pipes has been reached.
91 KErrNoMemory Insufficient memory to create pipe
92 KErrArgument If the specified size is negative or zero
93 otherwise one of the other system wide error code
97 // Check if the current handle is already opened for reading/writing
98 if ( iHandle && HandleType())
104 // Perform the capability check and create the channel
105 TInt err = DoCreate(Name(), VersionRequired(), KNullUnit, NULL, NULL, aType, ETrue);
109 // Create an un-named pipe with the specified size
110 err = DoControl(ECreateUnNamedPipe, (TAny*)&aSize);
113 iSize = DoControl(ESize);
114 iHandleType = EReadChannel;
126 EXPORT_C TInt RPipe::Open(RMessagePtr2 aMessage, TInt aParam, TOwnerType aType)
128 Opens a handle to pipe using a handle number sent by a client to a server.
129 This function is called by the server.
131 @param aMessage The message pointer.
133 @param aParam An index specifying which of the four message arguments contains the handle number.
135 @param aType An enumeration whose enumerators define the ownership of this logical channel handle.
136 If not explicitly specified, EOwnerProcess is taken as default.
137 @return KErrNone if successful;
138 KErrArgument if the value of aParam is outside the range 0-3;
139 KErrBadHandle if not a valid handle;
140 otherwise one of the other system-wide error codes.
145 TInt err = RBusLogicalChannel::Open(aMessage, aParam, aType);
150 err = DoControl(RPipe::EGetPipeInfo,&iHandleType,&iSize);
156 EXPORT_C TInt RPipe::Open(TInt aArgumentIndex, TOwnerType aType)
158 Opens the handle to pipe which is passed by a process to child process using
159 RProcess.SetParameter function call. Pipe handle type remains same(i.e. if read handle is passed
160 by process then read handle will be open).
162 @param aArgumentIndex An index that identifies the slot in the process environment
163 data that contains the handle number. This is a value relative
164 to zero, i.e. 0 is the first item/slot. This can range from 0 to 15.
166 @param aType The type of the handle to be created for the read/write end
168 @return KErrNone Pipe successfully created,
169 otherwise of the other system wide error code.
173 TInt err = RBusLogicalChannel::Open(aArgumentIndex,aType);
178 err = DoControl(RPipe::EGetPipeInfo,&iHandleType,&iSize);
182 TInt RPipe::Open(const RPipe& aReader, TOwnerType aType)
184 Opens a handle to write to a pipe. The pipe must have been created previously.
185 By default any thread in the process can use the handle to access to write to
186 the pipe. However, specifying EOwnerThread as the second parameter to this function,
187 means that only the opening thread can use this handle to write to the pipe.
189 @param aReader Handle to the reading end of the pipe.
191 @param aType The type of the handle to be created for the write end
193 @return KErrNone Pipe successfully created,
194 KErrInUse The current handle has already been opened
195 KErrAccessDenied The read handle is not open for reading
196 otherwise of the other system wide error code.
199 // Check if the current handle is already opened for reading/writing
200 if ( iHandle && HandleType())
203 // Check the read handle
205 if (aReader.HandleType() != EReadChannel)
206 return KErrAccessDenied;
208 // Perform the capability check and create the channel
209 TInt err = DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL, aType, ETrue);
213 // Obtained the handle number
214 TInt id = aReader.PipeHandle();
217 // Set the Write channel
218 err = DoControl(EOpenUnNamedPipe,(TAny*)&id);
222 iSize = DoControl(ESize);
223 iHandleType = EWriteChannel;
237 // Methods to Support Named Pipe
239 EXPORT_C TInt RPipe::Define(const TDesC& aName, TInt aSize)
241 Static method to create a new, named pipe of a given size. Calling this method
242 will create a new kernel object only. No user-side handles are created or opened.
244 @param aName Name to be assigned to the Kernel-side pipe object.
245 @param aSize Size of the pipe to create, in bytes.
247 @return KErrNone Pipe successfully created.
248 KErrBadName If the length of aName is greater than KMaxFileName
250 KErrOverflow Maximum number of pipes has been reached
251 KErrNoMemory Insufficient memory to create pipe.
252 KErrArgument if Size is negative
253 KErrAlreadyExist If a pipe with the specified name already exist.
254 otherwise one of the other system wide error code.
257 // Code to check a valid Name field as per Symbian naming convention
258 TInt err = User::ValidateName(aName);
262 if((aName.Length() > KMaxKernelName) || (aName.Length() == 0))
268 // Perform the capability check and create the channel
270 err = temp.DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL);
276 aInfo().isize = aSize;
277 aInfo().iName.Copy(aName);
279 // Define the Named pipe
280 err = temp.DoControl(EDefineNamedPipe, (TAny*)&aInfo);
287 EXPORT_C TInt RPipe::Define( const TDesC& aName, TInt aSize, const TSecurityPolicy& aPolicy)
289 Static method to create a new, named pipe of a given size. Calling this method
290 will create a new kernel object only. No user-side handles are created or opened.
292 @param aName Name to be assigned to the Kernel-side pipe object.
293 @param aSize Size of the pipe to create, in bytes.
295 @return KErrNone Pipe successfully created.
296 KErrBadName If the length of aName is greater than KMaxFileName
298 KErrOverflow Maximum number of pipes has been reached
299 KErrNoMemory Insufficient memory to create pipe.
300 KErrArgument if Size is negative
301 KErrPermissionDenied Not sufficient capabiliites
302 KErrAlreadyExist If a pipe with the specified name already exist.
303 otherwise one of the other system wide error code.
307 // Code to check a valid Name field as per Symbian naming convention
308 TInt err = User::ValidateName(aName);
312 if((aName.Length() > KMaxKernelName) || (aName.Length() == 0))
318 // Perform the capability check and create the channel
320 err = temp.DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL);
326 aInfo().isize = aSize;
327 aInfo().iName.Copy(aName);
328 err = temp.DoControl(EDefineNamedPipe, (TAny*)&aInfo, (TAny*)&aPolicy);
338 EXPORT_C TInt RPipe::Destroy( const TDesC& aName)
340 Static method to destroy a previously created named pipe. Any data not read from
341 the pipe will be discarded. This method will fail if there is any handles still
342 open on the pipe or the calling thread as insufficient capabilities.
344 @param aName Name of the Kernel-side pipe object to destroy
346 @return KErrNone Pipe successfully destroyed
347 KErrInUse The pipe still has one or more handle open to it
348 KErrPermissionDenied Not sufficient capabiliites
349 KErrNotFound If no kernel pipe exist with the specified name
350 otherwise one of the other system wide error code.
353 // Code to check a valid Name field as per Symbian naming convention
354 TInt err = User::ValidateName(aName);
358 if((aName.Length() > KMaxKernelName) || (aName.Length() == 0))
361 // Perform the capability check and create the channel
363 err = temp.DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL);
367 TBuf8<KMaxKernelName> name;
371 err = temp.DoControl(EDestroyNamedPipe, (TAny*)&name, NULL);
379 EXPORT_C TInt RPipe::Open(const TDesC& aName, TMode aMode)
381 Opens the pipe for the access mode specified. If the handle is opened to read or Write.
382 The handle is opened regardless of whether or not there is a open handle at the other end.
384 If the handle is opened as " Write but Fail On No Readers" the call will fail unless there
385 is atleast one handle open for reading at the other end.
387 @param aName Name of the kernel-side pipe object to destroy
388 @param aMode Access mode for the handle.
390 @return KErrNone Handle successfully opened.
391 KErrBadName If the length of aName is greater than KMaxFileName or Null
392 KErrInUse The pipe still has one or more handle open to it.
393 KErrPermissionDenied Not sufficient capabiliites
394 KErrNotFond If there is no kernel instance with the specified name
395 KErrNotReady Open Fails when no Readers is available while opening
396 With TMode = EOpenToWriteButFailOnNoReaders
397 otherwise one of the other system wide error code.
402 // Check if the current handle is already opened for reading/writing
403 if ( iHandle && HandleType())
406 TInt err = User::ValidateName(aName);
410 if((aName.Length() > KMaxKernelName) || (aName.Length() == 0))
413 // Perform the capability check and create the channel
414 err = DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL);
418 TBuf8<KMaxKernelName> name;
422 if (aMode == EOpenToRead)
424 err = DoControl(EOpenToReadNamedPipe,(TAny*)&name);
427 iSize = DoControl(ESize);
428 iHandleType = EReadChannel;
433 else if(aMode == EOpenToWrite)
435 err = DoControl(EOpenToWriteNamedPipe, (TAny*)&name);
438 iSize = DoControl(ESize);
439 iHandleType = EWriteChannel;
444 else if (aMode == EOpenToWriteNamedPipeButFailOnNoReaders)
446 err = DoControl(EOpenToWriteButFailOnNoReaderNamedPipe, (TAny*)&name);
449 iSize = DoControl(ESize);
450 iHandleType = EWriteChannel;
465 EXPORT_C void RPipe::Wait(const TDesC& aName, TRequestStatus& aStatus)
467 Block the thread until the other end of the pipe is opened for reading. If the other end
468 is already opened for reading the call will not block and status will complete immediately
469 This function will be deprecated , use WaitForReader.
470 Please note that Wait API will open a valid Write End of the pipe if not opened already.
471 User need not open write end of the pipe again after Wait call.
474 @param aName Name of the kernel-side pipe object to wait for
475 @param aStatus Status request that will complete when the other end is opened
478 @return KErrNone Request is successfully registered
479 KErrBadName If the length of aName is greater then KMaxFileName or NULL
480 KErrInUse A notifier of this type has already been registered.
481 KErrPermissionDenied Not sufficient capabiliites
482 otherwise one of the other system wide error code.
485 // To wait for Reader end pass flag as EWaitForReader.
486 TInt aFlag = EWaitForReader;
487 Wait(aName, aStatus , aFlag );
491 EXPORT_C void RPipe::CancelWait()
493 Cancel previous call to RPipe::Wait(), RPipe::WaitForReader (), RPipe::WaitForWriter ()
501 DoCancel(ECancelWaitNotification);
508 EXPORT_C void RPipe::Close()
510 Close the handle. This method exhibits different behaviour depending upon whether the pipe
512 Named pipes are allowed to persist without any open handles. Closing the last handle on a
513 named pipe will not destroy the kernel-side object. For an unnamed pipe, closing the last
514 handle will destroy the kernel-side pipe object. Any unread data in the pipe will be
516 An attempt to close an unnamed pipe will have no effect. Closing a handle will not affect
517 the state of any other handles that may be open on the pipe.
526 RHandleBase::Close();
532 EXPORT_C TInt RPipe::MaxSize()
534 Returns the total size, in bytes, of the Pipe
537 @return >= 0 Size of the pipe in bytes
538 KErrBadHandle The handle is not open
539 otherwise one of the other system wide error code.
543 return KErrBadHandle;
545 if(iHandleType == EReadChannel || iHandleType == EWriteChannel)
548 return KErrAccessDenied;
553 EXPORT_C TInt RPipe::Read(TDes8& aMsg, TInt aNumByte)
555 This is non-blocking synchronous method to read aNumByte bytes from the pipe into the
556 descriptor aMsg and returns the number of bytes read. If the pipe is empty the call will
557 immediately return a value of zero to indicate that no data was read
559 A successful RPipe::Read() operation will free up more space in the pipe.
561 @param aMsg Descriptor to receive data
562 @param aNumByte Number of bytes to be received.
564 @return >0 Amount of data read from the pipe, in bytes.
565 KErrUnderFlow The pipe was empty, no data was read
566 KErrAccessDenied An attempt has been made to read from a handle
567 has been opened for writing.
568 KErrBadHandle An attempt has been made to read from a handle
569 that has not been opened.
570 KErrNotReady Write end is closed and Pipe is empty.
571 0 No Data is available
572 otherwise one of the other system wide error code.
575 // Check for the error condition
577 return KErrBadHandle;
579 // Check for KErrArgument
580 if(aNumByte > aMsg.MaxLength())
583 if(iHandleType != EReadChannel)
584 return KErrAccessDenied;
586 return DoControl(ERead, (TAny*)&aMsg, (TAny*)&aNumByte);
592 EXPORT_C TInt RPipe::Write( const TDesC8& aData, TInt aNumByte)
594 This is non-blocking synchronous method to write data from aData. If the pipe is
595 full it will return immediately with KErrOverFlow
597 @param aData Descriptor from which data has to be written to the pipe
599 @return >0 Amount of data written to the pipe, in bytes
600 KErrAccessDenied An attempt has been made to write to a handle that
601 has been opened for reading.
602 KErrArgument If the size is more then aData's length
604 KErrOverFlow The pipe is full. No data was inserted into the pipe.
605 KErrBadHandle An attempt has been made to read from a handle that
607 KErrCompletion If the specified size is greater then the available size.
608 KErrNotReady Read end is closed.
609 otherwise one of the other system wide error code.
613 // Check for the error condition
615 return KErrBadHandle;
617 // Check for KErrArgument
618 if(aNumByte > aData.Length())
621 if(iHandleType == EReadChannel)
622 return KErrAccessDenied;
624 return DoControl(EWrite, (TAny*)&aData, (TAny*)&aNumByte);
629 EXPORT_C TInt RPipe::ReadBlocking( TDes8& aMsg, TInt aNumByte)
631 This is synchronous, blocking read operation. If the pipe is empty the client thread will
632 be blocked until data become available. A successful RPipe::ReadBlocking() operation will
633 free up more space in the pipe. This method is accompanied by data notification method to
634 complete the blocking mechanism
636 @param aMsg Descriptor to receive data
637 @param aNumByte Number of bytes to be received
639 @return >0 Amount of data read from the pipe in bytes.
640 KErrAccessDenied Am attempt has been made to read from the handle that
641 has been opened for writing.
642 KErrBadHandle Am attempt has been made to read from a handle that has
644 KErrArgument if the size is negative.
645 KErrInUse If the call is active from some another thread.
646 KErrNotReady Write end is closed and Pipe is empty.
647 otherwise one of the system wide error code.
651 TRequestStatus stat = KRequestPending;
654 // Check for the error condition
656 return KErrBadHandle;
661 if(iHandleType != EReadChannel)
662 return KErrAccessDenied;
664 // Asynchronous request to notify the data available.
667 stat = KRequestPending;
668 DoRequest(EReadBlocking, stat);
669 User::WaitForRequest(stat);
671 if (err == KErrInUse || err == KErrNotReady)
676 // Synchronous read operation
677 err = DoControl(ERead, (TAny*)&aMsg, (TAny*)&aNumByte);
678 if (err == KErrNotReady)
688 EXPORT_C TInt RPipe::WriteBlocking(const TDesC8& aData, TInt aNumByte)
690 This is a synchronous, blocking write operation. It will attempt to
691 write aNumByte's worth of data to the pipe, waiting till space is available.
692 If aNumByte is less than or equal to the pipe size, MaxSize(), the write
693 shall be atomic (w.r.t other threads sharing this channel), otherwise
694 the data will be split into multiple atomic writes of pipe size
695 (except, of course, if less than MaxSize bytes of data remain to be written).
697 @param aData Descriptor from which data has to be written to the pipe.
698 @param aNumByte Amount of data to be written to the pipe
700 @return >0 Amount of data written to the pipe, in bytes.
701 KErrAccessDenied An attempt has been made to write to a handle that
702 has been opened for reading.
703 KErrBadHandle An attempt has been made to read from a handle that has
705 KErrArgument if the size is negative.
706 KErrNotReady Read end is closed.
707 otherwise one of the other system wide error code.
711 TRequestStatus stat = KRequestPending;
718 // Check for the error condition
720 return KErrBadHandle;
727 if(iHandleType == EReadChannel)
728 return KErrAccessDenied;
730 if (aNumByte <= iSize)
731 writeindex = aNumByte;
737 // Asynchronous request to notify the space available.
738 stat = KRequestPending;
739 DoRequest(EWriteBlocking, stat,(TAny*)&writeindex);
740 User::WaitForRequest(stat);
742 if (err == KErrInUse || err == KErrNotReady)
747 // Synchronous write operation
748 tmp.Set(aData.Ptr()+index, writeindex);
749 err = DoControl(EWrite, (TAny*)&tmp, (TAny*)&writeindex);
750 if(err == KErrNotReady)
756 if ( err == aNumByte)
763 aNumByte = r - index;
765 writeindex = aNumByte;
774 EXPORT_C void RPipe::NotifyDataAvailable(TRequestStatus& aStatus)
776 This method registers the request status object to be completed when data become
777 available in the pipe.
779 @param aStatus Status request that will complete when Data is available.
781 @return KErrNone Successfully registered.
782 KErrAccessDenied Am attempt has been made to register a space available
783 notification on a handle that has not been opened for
785 KErrCompletion The request was NOT registered as the condition succeeded before wait.
786 KErrBadHandle The handle is not yet associated with a kernel pipe
787 otherwise of the other system wide error code.
797 else if(iHandleType != EReadChannel)
799 err = KErrAccessDenied;
803 ReqComplete(aStatus, err);
806 aStatus = KRequestPending;
807 DoRequest(EDataAvailable, aStatus);
813 EXPORT_C void RPipe::NotifySpaceAvailable(TInt aSize, TRequestStatus& aStatus)
815 This method registers the request status object to be completed when at least
816 aSize bytes are available for writing data into the pipe.
818 @param aSize Amount of space to wait for in the pipe.
819 @param aStatus Status request that will complete when aSize
820 bytes become available.
822 @returns KErrNone Successfully registered.
823 KErrAccessDenied An attempt has been made to register a space
824 available notification on a handle that has
825 not been opened for writing.
826 KErrArgument If the size is negative, zero, or greater than maximum pipe size
827 KErrBadHandle The handle is not yet associated with a kernel pipe
828 otherwise one of the other system wide error code
839 else if(iHandleType == EReadChannel)
841 err = KErrAccessDenied;
843 else if(aSize <= 0 || aSize > MaxSize())
850 ReqComplete(aStatus, err);
853 aStatus = KRequestPending;
854 DoRequest(ESpaceAvailable, aStatus, (TAny*)&aSize);
860 EXPORT_C TInt RPipe::CancelSpaceAvailable()
862 Cancels an outstanding space available notifier request.
866 @returns KErrNone Successfully cancelled the SpaceAvailable request.
867 KErrBadHandle An attempt has been made to Cancel Data Available with a
868 handle which has not been associated with any kernel pipe.
869 KErrAccessDenied An attempt has been made to cancel a space available
870 notification on a handle that has been opened for reading.
871 other wise on of the other system wide error code.
875 return KErrBadHandle;
877 if(iHandleType != EWriteChannel)
878 return KErrAccessDenied;
880 DoCancel(ECancelSpaceAvailable);
887 EXPORT_C TInt RPipe::CancelDataAvailable()
889 Cancels an outstanding data available notifier request.
892 @return KErrNone Successfully cancelled the DataAvailable request.
893 KErrBadHandle An attempt has been made to Cancel Data Available with a
894 handle which has not been associated with any kernel pipe.
895 KErrAccessDenied Am attempt has been made to cancel a data available
896 notification on a handle that has been opened for writing.
897 otherwise one of the other system wide error code
901 return KErrBadHandle;
903 if(iHandleType != EReadChannel)
904 return KErrAccessDenied;
906 DoCancel(ECancelDataAvailable);
912 EXPORT_C void RPipe::Flush()
914 This method will empty the pipe of all data
920 DoControl(EFlushPipe);
924 EXPORT_C TInt RPipe::HandleType()const
926 This method returns the Type of operation it can perform with the current handle.
929 EReadChannel If the current handle is associated to the kernel-side
930 pipe object as to perform Read operations.
931 EWriteChannel If the current handle is associated to the kernel-side
932 pipe object as to perform Write operations.
933 KErrBadHandle If the handle is not associated with Kernel-side object.
934 otherwise one of the other system wide error code
938 return KErrBadHandle;
944 EXPORT_C TInt RPipe::Size()
946 Returns the available data in the pipe
948 @return >= 0 Amount of data available in the pipe
949 KErrBadHandle The handle is not yet opened
950 otherwise one of the other system wide error code.
955 return KErrBadHandle;
957 return DoControl(EDataAvailableCount);
961 TInt RPipe::PipeHandle()const
963 Returns the id of Pipe it has created.
970 void RPipe::ReqComplete(TRequestStatus& aStatus, TInt err)
972 TRequestStatus* req=(&aStatus);
973 User::RequestComplete(req,err);
976 EXPORT_C void RPipe::WaitForReader(const TDesC& aName, TRequestStatus& aStatus)
978 Block the thread until the other end of the pipe is opened for reading. If the other end
979 is already opened for reading the call will not block and status will complete immediately.
981 Please note that WaitForReader API will open a valid Write End of the pipe if not opened already.
982 User need not open write end of the pipe again after WaitForReader call.
984 @param aName Name of the kernel-side pipe object to wait for
985 @param aStatus Status request that will complete when the other end is opened
988 @return KErrNone Request is successfully registered
989 KErrBadName If the length of aName is greater then KMaxFileName or NULL
990 KErrInUse A notifier of this type has already been registered.
991 KErrPermissionDenied Not sufficient capabiliites
992 KErrAccessDenied WaitForReader request is issued using Read handle.
993 otherwise one of the other system wide error code.
996 // To wait for Reader end pass flag as EWaitForReader.
997 TInt aFlag = EWaitForReader;
998 Wait(aName, aStatus , aFlag );
1001 EXPORT_C void RPipe::WaitForWriter(const TDesC& aName, TRequestStatus& aStatus)
1003 Block the thread until the other end of the pipe is opened for writing. If the other end
1004 is already opened for writing the call will not block and status will complete immediately
1006 Please note that WaitForWriter API will open a valid Read End of the pipe if not opened already.
1007 User need not open read end of the pipe again after WaitForWriter call.
1009 @param aName Name of the kernel-side pipe object to wait for
1010 @param aStatus Status request that will complete when the other end is opened
1013 @return KErrNone Request is successfully registered
1014 KErrBadName If the length of aName is greater then KMaxFileName or NULL
1015 KErrInUse A notifier of this type has already been registered.
1016 KErrPermissionDenied Not sufficient capabiliites
1017 KErrAccessDenied WaitForWriter request is issued using Write handle.
1018 otherwise one of the other system wide error code.
1021 // To wait for Writer end pass flag as EWaitForWriter.
1022 TInt aFlag = EWaitForWriter;
1023 Wait(aName, aStatus , aFlag );
1027 void RPipe::Wait(const TDesC& aName, TRequestStatus& aStatus , TInt aChoice)
1029 Block the thread until the other end of the pipe is opened for reading (or writing). If the other end
1030 is already opened for reading (or writing) the call will not block and status will complete immediately.
1034 @param aName Name of the kernel-side pipe object to wait for
1035 @param aStatus Status request that will complete when the other end is opened
1036 for reading (or Writing).
1037 @param aChoice EWaitForReader for WaitForReader.
1038 EWaitForWriter for WaitForWriter.
1040 @return KErrNone Request is successfully registered
1041 KErrBadName If the length of aName is greater then KMaxFileName or NULL
1042 KErrInUse A notifier of this type has already been registered.
1043 KErrPermissionDenied Not sufficient capabiliites
1044 KErrAccessDenied WaitForReader request is issued using Read handle or
1045 WaitForWriter request is issued using Write handle.
1046 otherwise one of the other system wide error code.
1050 // Code to check a valid Name field as per Symbian naming convention
1051 TInt err = User::ValidateName(aName);
1054 ReqComplete(aStatus, err);
1058 if((aName.Length() > KMaxKernelName) || (aName.Length() == 0))
1060 ReqComplete(aStatus, KErrBadName);
1064 TBuf8<KMaxKernelName> name8;
1067 aStatus = KRequestPending;
1068 // Check if the current instance of RPipe is already opened.
1071 // Perform the capability check and create the channel
1072 err = DoCreate(Name(),VersionRequired(), KNullUnit, NULL, NULL);
1075 ReqComplete(aStatus, err);
1079 if (aChoice == EWaitForReader)
1081 // Open the Write handle.
1082 err = DoControl(EOpenToWriteNamedPipe, (TAny*)&name8);
1085 iSize = DoControl(ESize);
1086 iHandleType = EWriteChannel;
1091 // Open the Read handle.
1092 err = DoControl(EOpenToReadNamedPipe, (TAny*)&name8);
1095 iSize = DoControl(ESize);
1096 iHandleType = EReadChannel;
1100 if ( err!= KErrNone)
1103 ReqComplete(aStatus, err);
1107 // use the existing Logical channel to send the request.
1108 DoRequest(EWaitNotification, aStatus, (TAny*)&name8,(TAny*)&aChoice);