jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.8KB

  1. #include <binder/Parcel.h>
  2. #include <utils/Log.h>
  3. #include "BpAndroidShm.h"
  4. namespace android{
  5. int BpAndroidShm::sendCommand(const char*command) {
  6. Parcel data, reply;
  7. data.writeInterfaceToken(
  8. IAndroidShm::getInterfaceDescriptor());
  9. data.writeCString(command);
  10. status_t status = remote()->transact(HW_SENDCOMMAND, data, &reply);
  11. if(status != NO_ERROR) {
  12. ALOGE("print sendCommand error: %s", strerror(-status));
  13. } else {
  14. status= reply.readInt32();
  15. }
  16. return status;
  17. }
  18. sp<IMemoryHeap> BpAndroidShm::getBuffer(int index) {
  19. Parcel data, reply;
  20. sp<IMemoryHeap> memHeap = NULL;
  21. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  22. data.writeInt32(index);
  23. remote()->transact(HW_GETBUFFER, data, &reply);
  24. memHeap = interface_cast<IMemoryHeap> (reply.readStrongBinder());
  25. return memHeap;
  26. }
  27. BpAndroidShm::BpAndroidShm( const sp<IBinder>& impl)
  28. : BpInterface<IAndroidShm>(impl)
  29. {}
  30. BpAndroidShm::~BpAndroidShm()
  31. {}
  32. int BpAndroidShm::allocShm(const int size) { // if negative return value is error
  33. Parcel data, reply;
  34. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  35. data.writeInt32(size);
  36. status_t status = remote()->transact(HW_ALLOC_SHM, data, &reply);
  37. if(status != NO_ERROR) {
  38. ALOGE("print allocShm error: %s", strerror(-status));
  39. } else {
  40. status= reply.readInt32();
  41. }
  42. return status;
  43. }
  44. int BpAndroidShm::removeShm(const unsigned int index) { // shared memory Á¦°Å
  45. Parcel data, reply;
  46. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  47. data.writeInt32(index);
  48. status_t status = remote()->transact(HW_REMOVE_SHM, data, &reply);
  49. if(status != NO_ERROR) {
  50. ALOGE("print removeShm error: %s", strerror(-status));
  51. } else {
  52. status= reply.readInt32();
  53. }
  54. return status;
  55. }
  56. int BpAndroidShm::isAllocated(const unsigned int index) { // allocated ¿©ºÎ È®ÀÎ
  57. Parcel data, reply;
  58. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  59. data.writeInt32(index);
  60. status_t status = remote()->transact(HW_IS_ALLOCATED, data, &reply);
  61. if(status != NO_ERROR) {
  62. ALOGE("print isAllocated error: %s", strerror(-status));
  63. } else {
  64. status= reply.readInt32();
  65. }
  66. return status;
  67. }
  68. int BpAndroidShm::setRegistryIndex(const unsigned int index) {
  69. Parcel data, reply;
  70. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  71. data.writeInt32(index);
  72. status_t status = remote()->transact(HW_SET_REGISTRY_INDEX, data, &reply);
  73. if(status != NO_ERROR) {
  74. ALOGE("print setRegistryIndex error: %s", strerror(-status));
  75. } else {
  76. status= reply.readInt32();
  77. }
  78. return status;
  79. }
  80. int BpAndroidShm::getRegistryIndex() {
  81. Parcel data, reply;
  82. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  83. status_t status = remote()->transact(HW_GET_REGISTRY_INDEX, data, &reply);
  84. if(status != NO_ERROR) {
  85. ALOGE("print getRegistryIndex error: %s", strerror(-status));
  86. } else {
  87. status= reply.readInt32();
  88. }
  89. return status;
  90. }
  91. sp<IMemoryHeap> BpAndroidShm::InitSemaphore(const char* name) {
  92. Parcel data, reply;
  93. sp<IMemoryHeap> memHeap = NULL;
  94. data.writeInterfaceToken(IAndroidShm::getInterfaceDescriptor());
  95. data.writeCString(name);
  96. status_t status = remote()->transact(HW_INIT_SEMAPHORE, data, &reply);
  97. memHeap = interface_cast<IMemoryHeap> (reply.readStrongBinder());
  98. return memHeap;
  99. }
  100. };