* 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;
}
#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_h* h) {
+ 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_h* h) {
+ 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 char* appid,
+ 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;
}