Home | History | Annotate | Download | only in mtp
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _MTP_PACKET_H
     18 #define _MTP_PACKET_H
     19 
     20 #include <android-base/macros.h>
     21 
     22 #include "MtpDebug.h"
     23 #include "MtpTypes.h"
     24 
     25 struct usb_device;
     26 struct usb_request;
     27 
     28 namespace android {
     29 
     30 class MtpPacket {
     31 
     32 protected:
     33     uint8_t*            mBuffer;
     34     // current size of the buffer
     35     size_t              mBufferSize;
     36     // number of bytes to add when resizing the buffer
     37     size_t              mAllocationIncrement;
     38     // size of the data in the packet
     39     size_t              mPacketSize;
     40 
     41 public:
     42     explicit            MtpPacket(int bufferSize);
     43     virtual             ~MtpPacket();
     44 
     45     // sets packet size to the default container size and sets buffer to zero
     46     virtual void        reset();
     47 
     48     void                allocate(size_t length);
     49     void                dump();
     50     void                copyFrom(const MtpPacket& src);
     51 
     52     uint16_t            getContainerCode() const;
     53     void                setContainerCode(uint16_t code);
     54 
     55     uint16_t            getContainerType() const;
     56 
     57     MtpTransactionID    getTransactionID() const;
     58     void                setTransactionID(MtpTransactionID id);
     59 
     60     uint32_t            getParameter(int index) const;
     61     void                setParameter(int index, uint32_t value);
     62 
     63 #ifdef MTP_HOST
     64     int                 transfer(struct usb_request* request);
     65 #endif
     66 
     67 protected:
     68     uint16_t            getUInt16(int offset) const;
     69     uint32_t            getUInt32(int offset) const;
     70     void                putUInt16(int offset, uint16_t value);
     71     void                putUInt32(int offset, uint32_t value);
     72 
     73     DISALLOW_COPY_AND_ASSIGN(MtpPacket);
     74 };
     75 
     76 }; // namespace android
     77 
     78 #endif // _MTP_PACKET_H
     79