summaryrefslogtreecommitdiff
path: root/android/AndroidShm.h
blob: b868827a8d3c14c1dff074f46890d7f70df194c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef ANDROIDSHM
#define ANDROIDSHM

#include <binder/Parcel.h>
#include "BnAndroidShm.h"
#include <utils/Log.h>
#include <binder/MemoryHeapBase.h>
#include "shm.h"
#include "android/Shm.h"  //android extension of shm.h

namespace android {

    class AndroidShm : public BnAndroidShm
    {
#define MAX_SHARED_MEMORY_COUNT 257
        private:
            int MemAlloc(unsigned int size);
        
        public:
            virtual ~AndroidShm();
            static int instantiate();
            virtual int sendCommand(const char* command);
            virtual int allocShm(const int size); // if negative return value is error
            virtual int removeShm(const unsigned int index); // shared memory Á¦°Å 
            virtual int isAllocated(const unsigned int index); // allocated ¿©ºÎ È®ÀÎ
            virtual int setRegistryIndex(const unsigned int index);
            virtual int getRegistryIndex();
            virtual sp<IMemoryHeap> InitSemaphore(const char* name);
            virtual sp<IMemoryHeap> getBuffer(int index);
            //virtual status_t onTransact(
            //        uint32_t code,
            //        const Parcel& data,
            //        Parcel* reply,
            //        uint32_t flags);
        private:
            int testGetBuffer();
            int testGetBufferByNewProcess();
            AndroidShm();

            sp<MemoryHeapBase> mMemHeap[MAX_SHARED_MEMORY_COUNT];
            unsigned int mRegistryIndex;

            // for named semaphore simulation
            #define MAX_SEMAPHORE_MEMORY_COUNT 300
            #define MAX_SEMAPHORE_NAME_LENGTH 300
            sp<MemoryHeapBase> mSemaphore[MAX_SEMAPHORE_MEMORY_COUNT];
            char mSemaphoreName[MAX_SEMAPHORE_MEMORY_COUNT][MAX_SEMAPHORE_NAME_LENGTH];
    };
};

#endif