SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" )
## SET C COMPILER FLAGS
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -fvisibility=hidden")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
## SET CPP COMPILER FLAGS
int rpc_port_stub_create_mockup(rpc_port_stub_h *h, const char *port_name);
+/**
+ * @brief Disconnects the port.
+ * @since_tizen 6.0
+ * @param[in] port The rpc port handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int rpc_port_disconnect(rpc_port_h port);
+
#ifdef __cplusplus
}
#endif
int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array,
unsigned int size);
+/**
+ * @brief Gets the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @remarks The @a header is managed by the platform and will be released when rpc_port_parcel_destroy() is called.
+ * @param[in] h The rpc port parcel handle
+ * @param[out] header The header handle of the rpc port parcel
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int rpc_port_parcel_get_header(rpc_port_parcel_h h, rpc_port_parcel_header_h *header);
+
+/**
+ * @brief Sets the tag to the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @param[in] header The header handle of the rpc port parcel
+ * @param[in] tag The tag
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see rpc_port_parcel_header_get_tag()
+ */
+int rpc_port_parcel_header_set_tag(rpc_port_parcel_header_h header, const char *tag);
+
+/**
+ * @brief Gets the tag from the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @remarks The @a tag should be released using free().
+ * @param[in] header The header handle of the rpc port parcel
+ * @param[out] tag The tag
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see rpc_port_parcel_header_set_tag()
+ */
+int rpc_port_parcel_header_get_tag(rpc_port_parcel_header_h header, char **tag);
+
+/**
+ * @brief Sets the sequence number to the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @param[in] header The header handle of the rpc port parcel
+ * @param[in] seq_num The sequence number
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see rpc_port_parcel_header_get_seq_num()
+ */
+int rpc_port_parcel_header_set_seq_num(rpc_port_parcel_header_h header, int seq_num);
+
+/**
+ * @brief Gets the sequence number from the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @param[in] header The header handle of the rpc port parcel
+ * @param[out] seq_num The sequence number
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see rpc_port_parcel_header_set_seq_num()
+ */
+int rpc_port_parcel_header_get_seq_num(rpc_port_parcel_header_h header, int *seq_num);
+
+/**
+ * @brief Gets the timestamp from the header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ * @remarks The @a timestamp represents monotonic time since some unspecified starting point.
+ * To get elapsed time properly, you have to get the timestamp using the clock_gettime() with CLOCK_MONITONIC_RAW.
+ * @param[in] header The header handle of the rpc port parcel
+ * @param[out] timestamp The timestamp
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int rpc_port_parcel_header_get_timestamp(rpc_port_parcel_header_h header, struct timespec *timestamp);
+
#ifdef __cplusplus
}
#endif
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2018 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
#define __TIZEN_APPFW_RPC_PORT_PARCEL_INCLUDE_H__
#include <stdbool.h>
+#include <sys/time.h>
+
#include <bundle.h>
#include <rpc-port.h>
typedef void *rpc_port_parcel_h;
/**
+ * @brief The header handle of the rpc port parcel.
+ * @since_tizen 6.0
+ */
+typedef void *rpc_port_parcel_header_h;
+
+/**
* @brief The interface for converting data to/from a parcel.
* @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
*/
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); /**< The function pointer to read from parcel */
+ void (*from)(rpc_port_parcel_h h, void *data); /**< The function pointer to write to parcel */
} rpc_port_parcelable_t;
/**
*/
int rpc_port_parcel_read(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable, void *data);
-
/**
* @brief Reads bytes from rpc port parcel handle.
* @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2018 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "parcel-header-internal.hh"
+
+#include <atomic>
+#include <climits>
+#include <limits>
+#include <string>
+#include <utility>
+
+namespace rpc_port {
+namespace internal {
+
+ParcelHeader::ParcelHeader() : seq_num_(GenerateSeqNum()) {
+ clock_gettime(CLOCK_MONOTONIC_RAW, &time_stamp_);
+}
+
+void ParcelHeader::SetTag(std::string tag) {
+ tag_ = std::move(tag);
+}
+
+const std::string& ParcelHeader::GetTag() const {
+ return tag_;
+}
+
+void ParcelHeader::SetSeqNum(int seq_num) {
+ seq_num_ = seq_num;
+}
+
+int ParcelHeader::GetSeqNum() const {
+ return seq_num_;
+}
+
+struct timespec ParcelHeader::GetTimeStamp() const {
+ return time_stamp_;
+}
+
+void ParcelHeader::SetTimeStamp(struct timespec time_stamp) {
+ time_stamp_ = time_stamp;
+}
+
+int ParcelHeader::GenerateSeqNum() {
+ static std::atomic<unsigned int> num{0};
+ ++num;
+ return static_cast<int>(num & INT_MAX);
+}
+
+} // namespace internal
+} // namespace rpc_port
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PARCEL_HEADER_INTERNAL_H_
+#define PARCEL_HEADER_INTERNAL_H_
+
+#include <time.h>
+
+#include <string>
+
+namespace rpc_port {
+namespace internal {
+
+class ParcelHeader {
+ public:
+ ParcelHeader();
+
+ void SetTag(std::string tag);
+ const std::string& GetTag() const;
+ void SetSeqNum(int seq_num);
+ int GetSeqNum() const;
+ struct timespec GetTimeStamp() const;
+ void SetTimeStamp(struct timespec time_stamp);
+ static int GenerateSeqNum();
+
+ private:
+ std::string tag_;
+ int seq_num_;
+ struct timespec time_stamp_;
+};
+
+} // namespace internal
+} // namespace rpc_port
+
+#endif // PARCEL_HEADER_INTERNAL_H_
*/
#include <cstring>
+#include "parcel-header-internal.hh"
#include "parcel-internal.h"
namespace rpc_port {
+namespace internal {
+
+Parcel::Parcel() {}
Parcel::Parcel(const unsigned char* buf, unsigned int size)
- : data_(buf, buf + size) {}
+ : data_(buf, buf + size) {
+ ReadParcelHeader();
+}
void Parcel::WriteByte(char b) {
Write<char>(b);
Write<int>(count);
}
+const std::vector<unsigned char> Parcel::MakeHeaderRaw() {
+ Parcel header_raw;
+ header_raw.WriteString(header_.GetTag().c_str());
+ header_raw.WriteInt32(header_.GetSeqNum());
+ header_raw.WriteInt64(static_cast<int64_t>(header_.GetTimeStamp().tv_sec));
+ header_raw.WriteInt64(static_cast<int64_t>(header_.GetTimeStamp().tv_nsec));
+
+ return std::move(header_raw.GetRaw());
+}
+
char Parcel::ReadByte() {
return Read<char>();
}
return Read<int>();
}
+void Parcel::ReadParcelHeader() {
+ header_.SetTag(std::move(ReadString()));
+ int seq_num = ReadInt32();
+ header_.SetSeqNum(seq_num);
+
+ struct timespec time_stamp {};
+ int64_t tv_sec = ReadInt64();
+ time_stamp.tv_sec = tv_sec & std::numeric_limits<time_t>::max();
+
+ int64_t tv_nsec = ReadInt64();
+ time_stamp.tv_nsec = tv_nsec & std::numeric_limits<long>::max();
+
+ header_.SetTimeStamp(time_stamp);
+}
+
const std::vector<unsigned char>& Parcel::GetRaw() {
return data_;
}
}
// LCOV_EXCL_STOP
+const ParcelHeader* Parcel::GetParcelHeader() {
+ return &header_;
+}
+
+} // namespace internal
} // namespace rpc_port
#include <algorithm>
#include <string>
+#include "parcel-header-internal.hh"
+
namespace rpc_port {
+namespace internal {
class Parcel {
public:
- Parcel() = default;
+ Parcel();
Parcel(const unsigned char* buf, unsigned int size);
void Write(const unsigned char* buf, unsigned int size);
void ResetReader();
void Clear();
void Reset(const unsigned char* buf, unsigned int size);
+ const ParcelHeader* GetParcelHeader();
+ const std::vector<unsigned char> MakeHeaderRaw();
+ void ReadParcelHeader();
private:
template<typename T>
}
private:
+ ParcelHeader header_;
std::vector<unsigned char> data_;
unsigned int reader_ = 0;
};
+} // namespace internal
} // namespace rpc_port
#endif // PARCEL_INTERNAL_H_
return RPC_PORT_ERROR_NONE;
}
+void Port::Disconnect() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (fd_ > 0) {
+ _W("Close fd(%d)", fd_);
+ close(fd_);
+ fd_ = -1;
+ }
+}
+
int Port::Read(void* buf, unsigned int size) {
unsigned int left = size;
ssize_t nb;
int SetPrivateSharing(const char* paths[], unsigned int size);
int SetPrivateSharing(const char* path);
int UnsetPrivateSharing();
+ void Disconnect();
int Read(void* buf, unsigned int size);
int Write(const void* buf, unsigned int size);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = new Parcel();
+ internal::Parcel* p = new internal::Parcel();
*h = p;
}
}
- Parcel* p = new Parcel(buf, len);
+ internal::Parcel* p = new internal::Parcel(buf, len);
delete[] buf;
*h = p;
if (h == nullptr || port == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
- int len = p->GetRaw().size();
-
- if (len <= 0)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
-
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
internal::Port* pt = static_cast<internal::Port*>(port);
{
std::lock_guard<std::recursive_mutex> lock(pt->GetMutex());
+ auto send_data = p->MakeHeaderRaw();
+ send_data.insert(send_data.end(), p->GetRaw().begin(), p->GetRaw().end());
+ int len = send_data.size();
+ if (len <= 0)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
int ret = rpc_port_write(port, &len, 4);
if (ret != 0)
return ret;
- ret = rpc_port_write(port, &*(p->GetRaw().cbegin()), len);
+ ret = rpc_port_write(port, &*(send_data.cbegin()), len);
if (ret != 0)
return ret;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- delete static_cast<Parcel*>(h);
+ delete static_cast<internal::Parcel*>(h);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteByte(b);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteInt16(i);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteInt32(i);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteInt64(i);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteFloat(f);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteDouble(d);
if (h == nullptr || str == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteString(str);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteBool(b);
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteBundle(b);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->WriteArrayCount(count);
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*b = p->ReadByte();
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*i = p->ReadInt16();
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*i = p->ReadInt32();
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*i = p->ReadInt64();
if (h == nullptr || f == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*f = p->ReadFloat();
if (h == nullptr || d == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*d = p->ReadDouble();
if (h == nullptr || str == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
const char* read = p->ReadString();
*str = read == nullptr ? strdup("") : strdup(read);
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*b = p->ReadBool();
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
bundle* read = p->ReadBundle();
*b = read == nullptr ? bundle_create() : read;
if (h == nullptr || count == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
*count = p->ReadArrayCount();
if (h == nullptr || buf == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->Read(buf, size);
if (h == nullptr || buf == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->Write(buf, size);
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->ResetReader();
if (h == nullptr || !array || !size)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
const auto& ptr = p->GetRaw();
void* array_ptr = malloc(ptr.size());
if (h == nullptr || !array || size == 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- Parcel* p = static_cast<Parcel*>(h);
+ internal::Parcel* p = static_cast<internal::Parcel*>(h);
p->Reset(reinterpret_cast<const unsigned char*>(array), size);
return RPC_PORT_ERROR_NONE;
}
// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_get_header(rpc_port_parcel_h h,
+ rpc_port_parcel_header_h* header) {
+ if (h == nullptr || header == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* parcel_header = parcel->GetParcelHeader();
+ *header = reinterpret_cast<rpc_port_parcel_header_h>(
+ const_cast<internal::ParcelHeader*>(parcel_header));
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_header_set_tag(rpc_port_parcel_header_h header,
+ const char* tag) {
+ if (header == nullptr || tag == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ parcel_header->SetTag(tag);
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_header_get_tag(rpc_port_parcel_header_h header,
+ char** tag) {
+ if (header == nullptr || tag == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ const std::string& raw_tag = parcel_header->GetTag();
+
+ *tag = strdup(raw_tag.c_str());
+ if (*tag == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY;
+
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_header_set_seq_num(rpc_port_parcel_header_h header,
+ int seq_num) {
+ if (header == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ parcel_header->SetSeqNum(seq_num);
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_header_get_seq_num(rpc_port_parcel_header_h header,
+ int* seq_num) {
+ if (header == nullptr || seq_num == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ *seq_num = parcel_header->GetSeqNum();
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_parcel_header_get_timestamp(
+ rpc_port_parcel_header_h header, struct timespec* timestamp) {
+ if (header == nullptr || timestamp == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ *timestamp = parcel_header->GetTimeStamp();
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
return port->UnsetPrivateSharing();
}
+
+// LCOV_EXCL_START
+RPC_API int rpc_port_disconnect(rpc_port_h h) {
+ if (h == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto port = static_cast<Port*>(h);
+ port->Disconnect();
+
+ return RPC_PORT_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
FOREACH(flag ${rpc-port_unittests_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
#include <stdbool.h>
#include <stdexcept>
-#include "rpc-port-parcel.h"
+#include "rpc-port-parcel-internal.h"
using ::testing::AtLeast;
ASSERT_EQ(buf[i], buf2[i]);
}
}
+
+/*
+ * @testcase rpc_port_parcel_get_header_P
+ * @description Gets the header handle from the rpc port parcel handle (internal)
+ * @apicovered rpc_port_parcel_get_header
+ */
+TEST_F(ParcelTest, rpc_port_parcel_get_header_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_NE(header, nullptr);
+}
+
+/*
+ * @testcase rpc_port_parcel_get_header_N
+ * @description Gets the header handle from the rpc port parcel handle (internal)
+ * @apicovered rpc_port_parcel_get_header
+ */
+TEST_F(ParcelTest, rpc_port_parcel_get_header_N) {
+ int ret = rpc_port_parcel_get_header(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_tag_P
+ * @description Sets and gets the tag (internal)
+ * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ const char tag[] = "1.5.0";
+ ret = rpc_port_parcel_header_set_tag(header, tag);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ char* out_tag = nullptr;
+ ret = rpc_port_parcel_header_get_tag(header, &out_tag);
+ std::unique_ptr<char, decltype(std::free)*> auto_free(out_tag, std::free);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_STREQ(tag, out_tag);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_tag_without_set_tag_P
+ * @description gets the tag without set tag. (internal)
+ * @apicovered rpc_port_parcel_header_get_tag
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_without_set_tag_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ char* out_tag = nullptr;
+ ret = rpc_port_parcel_header_get_tag(header, &out_tag);
+ std::unique_ptr<char, decltype(std::free)*> auto_free(out_tag, std::free);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_STREQ(out_tag, "");
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_tag_N
+ * @description Sets and gets the tag (internal)
+ * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_N) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ const char tag[] = "1.5.0";
+ ret = rpc_port_parcel_header_set_tag(nullptr, tag);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+
+ ret = rpc_port_parcel_header_set_tag(header, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+
+ char* out_tag = nullptr;
+ ret = rpc_port_parcel_header_get_tag(nullptr, &out_tag);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+
+ ret = rpc_port_parcel_header_get_tag(header, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_seq_num_P
+ * @description Sets and gets the sequence number (internal)
+ * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_parcel_header_set_seq_num(header, 100);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ int seq_num = 0;
+ ret = rpc_port_parcel_header_get_seq_num(header, &seq_num);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_EQ(seq_num, 100);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_seq_num_N
+ * @description Sets and gets the sequence number (internal)
+ * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_N) {
+ int ret = rpc_port_parcel_header_set_seq_num(nullptr, -1);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+
+ ret = rpc_port_parcel_header_get_seq_num(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_get_timestamp_P
+ * @description Gets the timestamp from the header handle of the rpc port parcel (internal)
+ * @apicovered rpc_port_parcel_header_get_timestamp
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ struct timespec timestamp = { 0, };
+ ret = rpc_port_parcel_header_get_timestamp(header, ×tamp);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ASSERT_NE(timestamp.tv_sec, 0);
+ ASSERT_NE(timestamp.tv_nsec, 0);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_get_timestamp_N
+ * @description Gets the timestamp from the header handle of the rpc port parcel (internal)
+ * @apicovered rpc_port_parcel_header_get_timestamp
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_N) {
+ int ret = rpc_port_parcel_header_get_timestamp(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
ret = rpc_port_stub_add_disconnected_event_cb(stub_handle_,
[](const char* sender, const char* instance, void *data) {
- RpcPortConnection* p = static_cast<RpcPortConnection*>(data);
+ auto* p = static_cast<RpcPortConnection*>(data);
p->touch_stub_disconnected_event_cb_ = true;
- p->Finish();
- }, this);
+ g_timeout_add(1, [](void* data) -> gboolean {
+ auto* p = static_cast<RpcPortConnection*>(data);
+ p->Finish();
+ return G_SOURCE_REMOVE;
+ }, p);
+ },
+ this);
ASSERT_EQ(ret, 0);
ret = rpc_port_stub_add_privilege(stub_handle_,
ASSERT_EQ(ret, 0);
ret = rpc_port_proxy_add_disconnected_event_cb(proxy_handle_,
- [](const char *ep, const char *port_name, void *data) {
- RpcPortConnection* p = static_cast<RpcPortConnection*>(data);
+ [](const char* ep, const char* port_name, void* data) {
+ auto* p = static_cast<RpcPortConnection*>(data);
p->touch_proxy_disconnected_event_cb_ = true;
- p->Finish();
- }, this);
+ g_timeout_add(1, [](void* data) -> gboolean {
+ auto* p = static_cast<RpcPortConnection*>(data);
+ p->Finish();
+ return G_SOURCE_REMOVE;
+ }, p);
+ },
+ this);
ASSERT_EQ(ret, 0);
ret = rpc_port_proxy_add_received_event_cb(proxy_handle_,
ASSERT_TRUE(touch_stub_disconnected_event_cb_);
}
+
+/*
+ * @testcase rpc_port_disconnect_P
+ * @description disconnect the port. (internal)
+ * And then, checks whether the disconnected event callback is invoked or not.
+ * @apicovered rpc_port_disconnect
+ */
+TEST_F(RpcPortConnection, rpc_port_disconnect_P) {
+ char res[] = "test";
+ if (proxy_port_ == nullptr)
+ RunMainLoop();
+
+ ASSERT_NE(proxy_port_, nullptr);
+ int ret = rpc_port_write(proxy_port_, res, sizeof(res));
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ if (stub_port_ == nullptr)
+ RunMainLoop();
+
+ ret = rpc_port_disconnect(stub_port_);
+ EXPECT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ RunMainLoop();
+ ASSERT_TRUE(touch_stub_disconnected_event_cb_);
+ ASSERT_TRUE(touch_proxy_disconnected_event_cb_);
+}
FOREACH(flag ${rpc-port-util_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -fPIE")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")