Implement APIs for rpc-port-parcel 90/161890/2
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 28 Nov 2017 05:52:23 +0000 (14:52 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 28 Nov 2017 05:57:18 +0000 (14:57 +0900)
Change-Id: I325777c0f2f14f861abde2a3ab4292bc68081add
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
include/rpc-port-parcel.h
include/rpc-port.h
src/parcel-internal.h
src/rpc-port-parcel.cc
src/rpc-port.cc

index b353510..847e0a5 100644 (file)
@@ -27,13 +27,13 @@ extern "C" {
 
 typedef void *rpc_port_parcel_h;
 typedef struct __rpc_port_parcelable {
-  void (*to)(rpc_port_parcel_h h, void *data);
-  void (*from)(rpc_port_parcel_h h, void *data);
+       void (*to)(rpc_port_parcel_h h, void *data);
+       void (*from)(rpc_port_parcel_h h, void *data);
 } rpc_port_parcelable_t;
 
 int rpc_port_parcel_create(rpc_port_parcel_h *h);
 int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port);
-int rpc_port_parcel_send(rpc_port_parcel_h *h, rpc_port_h port);
+int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port);
 int rpc_port_parcel_destroy(rpc_port_parcel_h h);
 int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b);
 int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i);
index 87db927..b66e677 100755 (executable)
@@ -25,8 +25,8 @@ extern "C" {
 typedef void *rpc_port_h;
 int rpc_port_open(int fd, rpc_port_h *h);
 int rpc_port_close(rpc_port_h h);
-int rpc_port_read(rpc_port_h h, char *buf, unsigned int size);
-int rpc_port_write(rpc_port_h h, char *buf, unsigned int size);
+int rpc_port_read(rpc_port_h h, void *buf, unsigned int size);
+int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size);
 
 /* proxy */
 typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep,
index f63960e..645cf36 100644 (file)
@@ -76,6 +76,6 @@ class Parcel {
   std::vector<unsigned char>::iterator reader_;
 };
 
-}
+}  // namespace rpc_port
 
 #endif  // __PARCEL_INTERNAL_H__
\ No newline at end of file
index 18953a1..0500268 100755 (executable)
  * limitations under the License.
  */
 
+#include <string.h>
+
 #include "rpc-port-parcel.h"
 
+#include "parcel-internal.h"
+
 #undef RPC_API
 #define RPC_API extern "C" __attribute__((visibility("default")))
 
-RPC_API int rpc_port_parcel_create(rpc_port_parcel_h *h) {
-       return 0;
+using namespace rpc_port;
+
+RPC_API int rpc_port_parcel_create(rpc_port_parcel_h* h) {
+  Parcel* p = new Parcel();
+
+  *h = p;
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h,
-               rpc_port_h port) {
-       return 0;
+RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h,
+    rpc_port_h port) {
+  int len;
+  unsigned char* buf;
+  int ret;
+
+  ret = rpc_port_read(port, &len, 4);
+  if (ret != 0)
+    return ret;
+
+  buf = new unsigned char[len];
+  ret = rpc_port_read(port, buf, len);
+  if (ret != 0) {
+    delete[] buf;
+    return ret;
+  }
+
+  Parcel* p = new Parcel(buf, len);
+  delete[] buf;
+
+  *h = p;
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_send(rpc_port_parcel_h *h, rpc_port_h port) {
-       return 0;
+RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) {
+  Parcel* p = static_cast<Parcel*>(h);
+  int len = p->GetRaw().size();
+  int ret;
+
+  if (len <= 0)
+    return -1;
+
+  ret = rpc_port_write(port, &len, 4);
+  if (ret != 0)
+    return ret;
+
+  ret = rpc_port_write(port, &*(p->GetRaw().cbegin()), len);
+  if (ret != 0)
+    return ret;
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  delete static_cast<Parcel*>(h);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteByte(b);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteInt16(i);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteInt32(i);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteInt64(i);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteFloat(f);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteDouble(d);
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str) {
-       return 0;
+RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteString(str);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteBool(b);
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b) {
-       return 0;
+RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteBundle(b);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count) {
-       return 0;
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  p->WriteArrayCount(count);
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h,
-               rpc_port_parcelable_t *parcelable, void *data) {
-       return 0;
+    rpc_port_parcelable_t* parcelable, void* data) {
+  if (parcelable == nullptr || parcelable->to == nullptr)
+    return -1;
+
+  if (h == nullptr)
+    return -1;
+
+  parcelable->to(h, data);
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b) {
-       return 0;
+RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *b = p->ReadByte();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i) {
-       return 0;
+RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short* i) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *i = p->ReadInt16();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i) {
-       return 0;
+RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *i = p->ReadInt32();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i) {
-       return 0;
+RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *i = p->ReadInt64();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f) {
-       return 0;
+RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float* f) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *f = p->ReadFloat();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d) {
-       return 0;
+RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double* d) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *d = p->ReadDouble();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str) {
-       return 0;
+RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *str = strdup(p->ReadString().c_str());
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b) {
-       return 0;
+RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool* b) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *b = p->ReadBool();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b) {
-       return 0;
+RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *b = p->ReadBundle();
+
+  return 0;
 }
 
-RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count) {
-       return 0;
+RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int* count) {
+  if (h == nullptr)
+    return -1;
+
+  Parcel* p = static_cast<Parcel*>(h);
+
+  *count = p->ReadArrayCount();
+
+  return 0;
 }
 
 RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h,
-               rpc_port_parcelable_t *parcelable, void *data) {
-       return 0;
+    rpc_port_parcelable_t* parcelable, void* data) {
+  if (parcelable == nullptr || parcelable->from == nullptr)
+    return -1;
+
+  if (h == nullptr)
+    return -1;
+
+  parcelable->from(h, data);
+
+  return 0;
 }
index 1a543ae..4292359 100755 (executable)
 #undef RPC_API
 #define RPC_API extern "C" __attribute__((visibility("default")))
 
-RPC_API int rpc_port_open(int fd, rpc_port_h *h) {
-       return 0;
+RPC_API int rpc_port_open(int fd, rpc_port_hh) {
+  return 0;
 }
 
 RPC_API int rpc_port_close(rpc_port_h h) {
-       return 0;
+  return 0;
 }
 
-RPC_API int rpc_port_read(rpc_port_h h, char *buf, unsigned int size) {
-       return 0;
+RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) {
+  return 0;
 }
 
-RPC_API int rpc_port_write(rpc_port_h h, char *buf, unsigned int size) {
-       return 0;
+RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) {
+  return 0;
 }
 
-RPC_API int rpc_port_proxy_create(rpc_port_proxy_h *h) {
-       return 0;
+RPC_API int rpc_port_proxy_create(rpc_port_proxy_hh) {
+  return 0;
 }
 
 RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
-       return 0;
+  return 0;
 }
 
-RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid,
-               const char *port) {
-       return 0;
+RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const charappid,
+    const char* port) {
+  return 0;
 }
 
 RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
-               rpc_port_proxy_connected_event_cb cb, void *data) {
-       return 0;
+    rpc_port_proxy_connected_event_cb cb, void *data) {
+  return 0;
 }
 
 RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
-               rpc_port_proxy_disconnected_event_cb cb, void *data) {
-       return 0;
+    rpc_port_proxy_disconnected_event_cb cb, void* data) {
+  return 0;
 }
 
 RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
-               rpc_port_proxy_rejected_event_cb cb, void *data) {
-       return 0;
+    rpc_port_proxy_rejected_event_cb cb, void* data) {
+  return 0;
 }
 
-RPC_API int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name) {
-       return 0;
+RPC_API int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name) {
+  return 0;
 }
 
 RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
-       return 0;
+  return 0;
 }
 
 RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) {
-       return 0;
+  return 0;
 }
 
 RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
-               rpc_port_stub_connected_event_cb cb, void *data) {
-       return 0;
+    rpc_port_stub_connected_event_cb cb, void* data) {
+  return 0;
 }
 
 RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
-               rpc_port_stub_disconnected_event_cb cb, void *data) {
-       return 0;
+    rpc_port_stub_disconnected_event_cb cb, void* data) {
+  return 0;
 }
 
 RPC_API int rpc_port_stub_add_recevied_event_cb(rpc_port_stub_h h,
-               rpc_port_stub_received_event_cb cb, void *data) {
-       return 0;
+    rpc_port_stub_received_event_cb cb, void* data) {
+  return 0;
 }