javacommons/gcfbase/inc/nativestreambase.h
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Base class for all native implementation of stream types
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NATIVESTREAMBASE_H
       
    20 #define NATIVESTREAMBASE_H
       
    21 
       
    22 #include <jni.h>
       
    23 
       
    24 namespace java
       
    25 {
       
    26 
       
    27 /**
       
    28 * This is the base class for Native Peer of streams.
       
    29 * StreamConnectionBase in will make calls to the native side to get/send data.
       
    30 * It will have stored a handle to the Object and uses it to call these methods.
       
    31 *
       
    32 * Usage:
       
    33 * Please ensure that this class comes first in the line of inheritance as shown.
       
    34 *
       
    35 * @code
       
    36 * class StreamConnectionX : public NativeStreamBase, public AllOtherClasses
       
    37 * @endcode
       
    38 *
       
    39 */
       
    40 class NativeStreamBase
       
    41 {
       
    42 public:
       
    43     /**
       
    44     * ReadBytes is called once the buffer at the InputStream in Java runs
       
    45     * out of data.
       
    46     * How this function should be called.
       
    47     * @param[in]  aJavaBuffer: A byte array of length 512 bytes
       
    48     * @return return should be the number of bytes read. If error, then the
       
    49     *         value of errno should be negated and returned. (return -errno)
       
    50     */
       
    51     virtual int readBytes(JNIEnv& aJni, jbyteArray aJavaBuffer) = 0;
       
    52 
       
    53     /**
       
    54     * WriteBytes is called once buffer at the OutputStream in Java overflows.
       
    55     * It is also called if flush() is called at the Java side.
       
    56     * How this function should be called.
       
    57     * @param[in]  aJavaBuffer: A byte array of length aLength
       
    58     * @return return should be the number of bytes written. If error, then the
       
    59     *         value of errno should be negated and returned. (return -errno)
       
    60     */
       
    61     virtual int writeBytes(JNIEnv& aJni, jbyteArray aJavaBuffer,
       
    62                            int aOffset, int aLength) = 0;
       
    63 
       
    64     /**
       
    65     * StopReading is called once InputStream is closed from the Application.
       
    66     */
       
    67     virtual void stopReading() = 0;
       
    68 
       
    69     /**
       
    70     * StopWriting is called once OutputStream is closed from the Application.
       
    71     */
       
    72     virtual void stopWriting() = 0;
       
    73 
       
    74     /**
       
    75     * Defines the size of the buffer to be held on the native side. Should be
       
    76     * same as the buffer in the InputStream
       
    77     */
       
    78     int mBufferSize;
       
    79 
       
    80     /**
       
    81      * SetBufferSize is called during StreamConnectionBase construction.
       
    82      * This is to keep both Java and Native Buffers in sync.
       
    83      */
       
    84     void setBufferSize(int aSize)
       
    85     {
       
    86         mBufferSize = aSize;
       
    87     }
       
    88 
       
    89     virtual int available()
       
    90     {
       
    91         return 0;
       
    92     }
       
    93 };
       
    94 
       
    95 }  //end namespace java
       
    96 
       
    97 
       
    98 #endif // NATIVESTREAMBASE_H