Skip to content

Commit

Permalink
Merge pull request #397 from na-trium-144/log_entry
Browse files Browse the repository at this point in the history
Log entry
  • Loading branch information
na-trium-144 authored Sep 3, 2024
2 parents 0bccf85 + 56fdbb0 commit c282f8e
Show file tree
Hide file tree
Showing 37 changed files with 522 additions and 131 deletions.
10 changes: 10 additions & 0 deletions client/include/webcface/canvas2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ class WEBCFACE_DLL Canvas2D : protected Field {
std::vector<Canvas2DComponent> get() const {
return tryGet().value_or(std::vector<Canvas2DComponent>{});
}
/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;

/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime()に変更
Expand Down
10 changes: 10 additions & 0 deletions client/include/webcface/canvas3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class WEBCFACE_DLL Canvas3D : protected Field {
std::vector<Canvas3DComponent> get() const {
return tryGet().value_or(std::vector<Canvas3DComponent>{});
}
/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;

/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime()に変更
Expand Down
7 changes: 7 additions & 0 deletions client/include/webcface/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ class WEBCFACE_DLL Func : protected Field {
}
Promise runAsync(std::vector<ValAdaptor> args_vec) const;

/*!
* \brief 関数の情報が存在すればtrue
* \since ver2.1
*
*/
bool exists() const;

/*!
* \brief 戻り値の型を返す
*
Expand Down
10 changes: 10 additions & 0 deletions client/include/webcface/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ class WEBCFACE_DLL Image : protected Field {

// operator ImageFrame() const { return get(); }

/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;

/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime()に変更
Expand Down
22 changes: 22 additions & 0 deletions client/include/webcface/internal/data_store1.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class SyncDataStore1 {
StrMap1<T> data_recv;
StrMap1<bool> req;
StrMap1<bool> req_send;
/*!
* \brief 受信済みのentry
*
* entry[member名] = {データ名のリスト}
*
*/
StrSet1 entry;

public:
SharedString self_member_name;
Expand All @@ -34,6 +41,21 @@ class SyncDataStore1 {

void setRecv(const SharedString &member, const T &data);

/*!
* \brief memberのentryをクリア
*/
void clearEntry(const SharedString &from);
/*!
* \brief 受信したentryを追加
*/
void setEntry(const SharedString &from);

/*!
* \brief entryを取得
*/
bool getEntry(const SharedString &from);
bool getEntry(const FieldBase &base);

std::optional<T> getRecv(const SharedString &member);
//! req_sendを返し、req_sendをクリア
StrMap1<bool> transferReq();
Expand Down
9 changes: 9 additions & 0 deletions client/include/webcface/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ class WEBCFACE_DLL Log : protected Field {
return tryGetW().value_or(std::vector<LogLineW>{});
}

/*!
* \brief このメンバーがログを1行以上出力していればtrue
* \since ver2.1
*
* tryGet(), get().size() などとは違って、実際のログデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;
/*!
* \brief 受信したログをクリアする
* \since ver1.1.5
Expand Down
9 changes: 9 additions & 0 deletions client/include/webcface/robot_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class WEBCFACE_DLL RobotModel : protected Field {
return tryGet().value_or(std::vector<RobotLink>{});
}
operator std::vector<RobotLink>() const { return get(); }
/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;
/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime() に変更
Expand Down
10 changes: 10 additions & 0 deletions client/include/webcface/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ class WEBCFACE_DLL Text : protected Variant {
operator const std::string &() const { return get(); }
operator const std::wstring &() const { return getW(); }

/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;

/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime()に変更
Expand Down
10 changes: 10 additions & 0 deletions client/include/webcface/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ class WEBCFACE_DLL Value : protected Field {
}
operator double() const { return get(); }
operator std::vector<double>() const { return getVec(); }

/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;
/*!
* \brief syncの時刻を返す
* \deprecated 1.7で Member::syncTime() に変更
Expand Down
9 changes: 9 additions & 0 deletions client/include/webcface/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ class WEBCFACE_DLL View : protected Field {
std::vector<ViewComponent> get() const {
return tryGet().value_or(std::vector<ViewComponent>{});
}
/*!
* \brief このフィールドにデータが存在すればtrue
* \since ver2.1
*
* tryGet() などとは違って、実際のデータを受信しない。
* リクエストも送信しない。
*
*/
bool exists() const;
/*!
* \brief syncの時刻を返す
* \deprecated 1.7でMember::syncTime()に変更
Expand Down
3 changes: 3 additions & 0 deletions client/src/canvas2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ const Canvas2D &Canvas2D::free() const {
}
return *this;
}
bool Canvas2D::exists() const {
return dataLock()->canvas2d_store.getEntry(member_).count(field_);
}

WEBCFACE_NS_END
3 changes: 3 additions & 0 deletions client/src/canvas3d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,8 @@ const Canvas3D &Canvas3D::free() const {
}
return *this;
}
bool Canvas3D::exists() const {
return dataLock()->canvas3d_store.getEntry(member_).count(field_);
}

WEBCFACE_NS_END
16 changes: 16 additions & 0 deletions client/src/client_msg_recv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ void internal::ClientData::onRecv(const std::string &message) {
this->robot_model_store.clearEntry(r.member_name);
this->canvas3d_store.clearEntry(r.member_name);
this->canvas2d_store.clearEntry(r.member_name);
this->log_store.clearEntry(r.member_name);
this->member_ids[r.member_name] = r.member_id;
this->member_lib_name[r.member_id] = r.lib_name;
this->member_lib_ver[r.member_id] = r.lib_ver;
Expand Down Expand Up @@ -433,6 +434,21 @@ void internal::ClientData::onRecv(const std::string &message) {
onRecvEntry(this, r, this->image_store, this->image_entry_event);
break;
}
case MessageKind::log_entry: {
auto &r = *static_cast<webcface::message::LogEntry *>(obj.get());
auto member = this->getMemberNameFromId(r.member_id);
this->log_store.setEntry(member);
// std::decay_t<decltype(this->log_entry_event.at(member))> cl;
// {
// std::lock_guard lock(this->event_m);
// cl = findFromMap1(this->log_entry_event,
// member).value_or(nullptr);
// }
// if (cl && *cl) {
// cl->operator()(Field{this->shared_from_this(), member});
// }
break;
}
case MessageKind::func_info: {
auto &r = *static_cast<webcface::message::FuncInfo *>(obj.get());
auto member = this->getMemberNameFromId(r.member_id);
Expand Down
21 changes: 21 additions & 0 deletions client/src/data_store1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ void SyncDataStore1<T>::setRecv(const SharedString &member, const T &data) {
data_recv[member] = data;
}

template <typename T>
void SyncDataStore1<T>::clearEntry(const SharedString &from) {
std::lock_guard lock(mtx);
entry.erase(from);
}
template <typename T>
void SyncDataStore1<T>::setEntry(const SharedString &from) {
std::lock_guard lock(mtx);
entry.emplace(from);
}
template <typename T>
bool SyncDataStore1<T>::getEntry(const SharedString &from) {
std::lock_guard lock(mtx);
return entry.count(from) > 0;
}
template <typename T>
bool SyncDataStore1<T>::getEntry(const FieldBase &base) {
std::lock_guard lock(mtx);
return entry.count(base.member_) > 0;
}

template <typename T>
bool SyncDataStore1<T>::addReq(const SharedString &member) {
std::lock_guard lock(mtx);
Expand Down
3 changes: 3 additions & 0 deletions client/src/func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ std::vector<Arg> Func::args() const {
}
return std::vector<Arg>{};
}
bool Func::exists() const {
return dataLock()->func_store.getEntry(member_).count(field_);
}

const Func &Func::setArgs(const std::vector<Arg> &args) const {
auto func_info = setCheck()->func_store.getRecv(*this);
Expand Down
3 changes: 3 additions & 0 deletions client/src/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@ const Image &Image::free() const {
}
return *this;
}
bool Image::exists() const {
return dataLock()->image_store.getEntry(member_).count(field_);
}

WEBCFACE_NS_END
2 changes: 2 additions & 0 deletions client/src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ std::optional<std::vector<LogLineW>> Log::tryGetW() const {
}
}

bool Log::exists() const { return dataLock()->log_store.getEntry(member_); }

const Log &Log::clear() const {
dataLock()->log_store.setRecv(member_,
std::make_shared<std::vector<LogLineData>>());
Expand Down
3 changes: 3 additions & 0 deletions client/src/robot_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,8 @@ const RobotModel &RobotModel::free() const {
}
return *this;
}
bool RobotModel::exists() const {
return dataLock()->robot_model_store.getEntry(member_).count(field_);
}

WEBCFACE_NS_END
4 changes: 4 additions & 0 deletions client/src/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ const Text &Text::free() const {
return *this;
}

bool Text::exists() const {
return dataLock()->text_store.getEntry(member_).count(field_);
}

std::ostream &operator<<(std::ostream &os, const Text &data) {
return os << data.get();
}
Expand Down
4 changes: 4 additions & 0 deletions client/src/value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ const Value &Value::free() const {
return *this;
}

bool Value::exists() const {
return dataLock()->value_store.getEntry(member_).count(field_);
}

std::ostream &operator<<(std::ostream &os, const Value &data) {
auto v = data.tryGetVec();
if (v) {
Expand Down
3 changes: 3 additions & 0 deletions client/src/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,8 @@ const View &View::free() const {
}
return *this;
}
bool View::exists() const {
return dataLock()->view_store.getEntry(member_).count(field_);
}

WEBCFACE_NS_END
19 changes: 17 additions & 2 deletions docs/51_value.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ wcli.value("a").set(a_instance); // Dictにキャストされる
const hoge: double[] | null = wcli.member("foo").value("hoge").tryGetVec();
```
* 値を受信していない場合 tryGet(), tryGetVec() はnullを返し、そのデータのリクエストをサーバーに送ります。
* リクエストは <del>次にClient::sync()したときに</del>
* リクエストは <del>次にClient.sync()したときに</del>
<span class="since-js">1.1</span>自動的に別スレッドで送信されます。
* そのデータを受信した後([4-1. Client](./41_client.md)を参照)、再度tryGet()することで値が得られます。
* get(), getVec() はnullの代わりに0を返します。
Expand Down Expand Up @@ -420,6 +420,13 @@ wcli.value("a").set(a_instance); // Dictにキャストされる

### Entry

データ自体はすべて受信しなくても、データが存在するかどうか(他memberが送信しているかどうか)は取得することができます。

\warning
<span class="since-c">1.10</span>
半角ピリオドから始まる名前のデータはEntryが送信されないため、
明示的に名前を指定して受信することはできても、以下の方法でデータが存在するかどうかを確認することはできません。

<div class="tabbed">

- <b class="tab-title">C++</b>
Expand All @@ -441,6 +448,10 @@ wcli.value("a").set(a_instance); // Dictにキャストされる
// pos.x, pos.y などのvalueが得られる
```

<span class="since-c">2.1</span>
Value::exists() でそのデータが送信されているかどうかを確認できます。
tryGet() と違い、データそのものを受信するリクエストは送られません。

- <b class="tab-title">C</b>
\since <span class="since-c">2.0</span>

Expand All @@ -460,6 +471,10 @@ wcli.value("a").set(a_instance); // Dictにキャストされる
}
```

<span class="since-js">1.8</span>
Value.exists() でそのデータが送信されているかどうかを確認できます。
tryGet() と違い、データそのものを受信するリクエストは送られません。

- <b class="tab-title">Python</b>
<del>Member.values() で</del> そのMemberが送信しているvalueのリストが得られます
<span class="since-py">1.1</span>
Expand All @@ -472,7 +487,7 @@ wcli.value("a").set(a_instance); // Dictにキャストされる

</div>

## ValueEntry イベント
### ValueEntry イベント

他のメンバーが新しくデータを追加したときに呼び出されるコールバックを設定できます。

Expand Down
Loading

0 comments on commit c282f8e

Please sign in to comment.