Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

launcher update #410

Merged
merged 10 commits into from
Oct 2, 2024
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [2.4.0] - 2024-10-02
### Changed
* Logメッセージを仕様変更、Logに名前をつけて複数送信できるようになった (#410)
* ver2.3以前のサーバーと2.4以降のクライアントの間ではLogを送受信できなくなります
* Funcに登録した引数にCallHandleをとる関数がthrowしたときそれをcatchしてrejectする
### Added
* Func::set() で引数にCallHandleをとる関数を渡してセットし、その後からsetArgs()などオプションを使う使い方
* Field::logEntries()
* Member::onLogEntry()

## [2.3.0] - 2024-09-17
### Fixed
* ver2.2.1以降でserverがセグフォすることがあったバグを修正 (#407)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(webcface VERSION 2.3.0)
project(webcface VERSION 2.4.0)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(IS_MAIN on)
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "WebCFace"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "2.3.0"
PROJECT_NUMBER = "2.4.0"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ WebCFaceの通信データ形式はOSやライブラリの言語によらず共
つまり、異なるバージョンのクライアント同士でも、異なるバージョンのOSでも問題なく通信が可能です。
(C++のver1.1.6以前を除く)
ただしそれぞれのクライアントのバージョンよりサーバーの方が新しいバージョンである必要があります。
サーバーよりクライアントのほうが新しい場合の動作は保証しません。

### WebUI

Expand Down Expand Up @@ -194,9 +195,9 @@ Ubuntu20.04でビルドしているため、それより古いUbuntuでは動作
<details open><summary>x86_64</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.3.0/webcface_2.3.0_linux_amd64.zip
sudo unzip webcface_2.3.0_linux_amd64.zip -d /opt/webcface
rm webcface_2.3.0_linux_amd64.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.4.0/webcface_2.4.0_linux_amd64.zip
sudo unzip webcface_2.4.0_linux_amd64.zip -d /opt/webcface
rm webcface_2.4.0_linux_amd64.zip
echo 'export PATH="/opt/webcface/bin:$PATH"' >> ~/.bashrc
echo 'export PKG_CONFIG_PATH="/opt/webcface/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.bashrc
sudo ln -sf /opt/webcface/lib/systemd/system/*.service /etc/systemd/system/
Expand All @@ -206,9 +207,9 @@ sudo ln -sf /opt/webcface/lib/systemd/system/*.service /etc/systemd/system/
<details><summary>arm64</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.3.0/webcface_2.3.0_linux_arm64.zip
sudo unzip webcface_2.3.0_linux_arm64.zip -d /opt/webcface
rm webcface_2.3.0_linux_arm64.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.4.0/webcface_2.4.0_linux_arm64.zip
sudo unzip webcface_2.4.0_linux_arm64.zip -d /opt/webcface
rm webcface_2.4.0_linux_arm64.zip
echo 'export PATH="/opt/webcface/bin:$PATH"' >> ~/.bashrc
echo 'export PKG_CONFIG_PATH="/opt/webcface/lib/aarch64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.bashrc
sudo ln -sf /opt/webcface/lib/systemd/system/*.service /etc/systemd/system/
Expand All @@ -218,9 +219,9 @@ sudo ln -sf /opt/webcface/lib/systemd/system/*.service /etc/systemd/system/
<details><summary>armhf</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.3.0/webcface_2.3.0_linux_armhf.zip
sudo unzip webcface_2.3.0_linux_armhf.zip -d /opt/webcface
rm webcface_2.3.0_linux_armhf.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.4.0/webcface_2.4.0_linux_armhf.zip
sudo unzip webcface_2.4.0_linux_armhf.zip -d /opt/webcface
rm webcface_2.4.0_linux_armhf.zip
echo 'export PATH="/opt/webcface/bin:$PATH"' >> ~/.bashrc
echo 'export PKG_CONFIG_PATH="/opt/webcface/lib/arm-linux-gnueabihf/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.bashrc
sudo ln -sf /opt/webcface/lib/systemd/system/*.service /etc/systemd/system/
Expand All @@ -241,10 +242,10 @@ Ubuntu20.04でビルドしているため、それより古いUbuntuでは動作
<details open><summary>x86_64</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.3.0/webcface_2.3.0_amd64.deb
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.4.0/webcface_2.4.0_amd64.deb
curl -fLO https://github.com/na-trium-144/webcface-tools/releases/download/v2.0.1/webcface-tools_2.0.1_amd64.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-webui_1.8.3_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-desktop_1.8.3_linux_amd64.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-webui_1.9.0_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-desktop_1.9.0_linux_amd64.deb
sudo apt install ./webcface*.deb
rm ./webcface*.deb
```
Expand All @@ -253,10 +254,10 @@ rm ./webcface*.deb
<details><summary>arm64</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.3.0/webcface_2.3.0_arm64.deb
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.4.0/webcface_2.4.0_arm64.deb
curl -fLO https://github.com/na-trium-144/webcface-tools/releases/download/v2.0.1/webcface-tools_2.0.1_arm64.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-webui_1.8.3_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-desktop_1.8.3_linux_arm64.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-webui_1.9.0_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-desktop_1.9.0_linux_arm64.deb
sudo apt install ./webcface*.deb
rm ./webcface*.deb
```
Expand All @@ -265,10 +266,10 @@ rm ./webcface*.deb
<details><summary>armhf</summary>

```sh
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.3.0/webcface_2.3.0_armhf.deb
curl -fLO https://github.com/na-trium-144/webcface/releases/download/v2.4.0/webcface_2.4.0_armhf.deb
curl -fLO https://github.com/na-trium-144/webcface-tools/releases/download/v2.0.1/webcface-tools_2.0.1_armhf.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-webui_1.8.3_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.8.3/webcface-desktop_1.8.3_linux_armv7l.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-webui_1.9.0_all.deb
curl -fLO https://github.com/na-trium-144/webcface-webui/releases/download/v1.9.0/webcface-desktop_1.9.0_linux_armv7l.deb
sudo apt install ./webcface*.deb
rm ./webcface*.deb
```
Expand All @@ -287,16 +288,16 @@ Universalバイナリになっており、IntelMacもAppleシリコンも共通
macOS 12 (Monterey) でビルドしているので、それより古いMacでは動かないかもしれません。

```sh
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.3.0/webcface_2.3.0_macos_universal.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.3.0/webcface-desktop_2.3.0_macos_app.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.4.0/webcface_2.4.0_macos_universal.zip
curl -fLO https://github.com/na-trium-144/webcface-package/releases/download/v2.4.0/webcface-desktop_2.4.0_macos_app.zip
```

sudo権限が使用できれば以下のように webcface_universal を /opt/webcface に、 webcface-desktop_app を /Applications に展開するのがおすすめです。
```sh
sudo unzip webcface_2.3.0_macos_universal.zip -d /opt/webcface
sudo unzip webcface-desktop_2.3.0_macos_app.zip -d /Applications
rm webcface_2.3.0_macos_universal.zip
rm webcface-desktop_2.3.0_macos_app.zip
sudo unzip webcface_2.4.0_macos_universal.zip -d /opt/webcface
sudo unzip webcface-desktop_2.4.0_macos_app.zip -d /Applications
rm webcface_2.4.0_macos_universal.zip
rm webcface-desktop_2.4.0_macos_app.zip
```

また、展開したディレクトリ内の bin/ をPATHに、 lib/pkgconfig/ をPKG_CONFIG_PATHに追加してください。
Expand Down
34 changes: 33 additions & 1 deletion client/include/webcface/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class WEBCFACE_DLL Client : public Member {
/*!
* \brief サーバーに接続されている他のmemberのリストを得る。
* \since ver2.0.2 (constつけ忘れ)
*
*
* 自分自身と、無名のmemberを除く。
* \sa member(), onMemberEntry()
*/
Expand Down Expand Up @@ -271,6 +271,14 @@ class WEBCFACE_DLL Client : public Member {
* \sa loggerOStream()
*/
std::streambuf *loggerStreamBuf() const;
/*!
* \brief webcfaceに出力するstreambuf
* \since ver2.4
*
* * nameを省略した場合 "default" になる。
*
*/
std::streambuf *loggerStreamBuf(std::string_view name) const;
/*!
* \brief webcfaceに出力するostream
*
Expand All @@ -284,18 +292,42 @@ class WEBCFACE_DLL Client : public Member {
* \sa loggerStreamBuf()
*/
std::ostream &loggerOStream() const;
/*!
* \brief webcfaceに出力するostream
* \since ver2.4
*
* * nameを省略した場合 "default" になる。
*
*/
std::ostream &loggerOStream(std::string_view name) const;
/*!
* \brief webcfaceに出力するwstreambuf
* \since ver2.0
* \sa loggerStreamBuf
*/
std::wstreambuf *loggerWStreamBuf() const;
/*!
* \brief webcfaceに出力するwstreambuf
* \since ver2.4
*
* * nameを省略した場合 "default" になる。
*
*/
std::wstreambuf *loggerWStreamBuf(std::wstring_view name) const;
/*!
* \brief webcfaceに出力するwostream
* \since ver2.0
* \sa loggerOStream
*/
std::wostream &loggerWOStream() const;
/*!
* \brief webcfaceに出力するwostream
* \since ver2.4
*
* * nameを省略した場合 "default" になる。
*
*/
std::wostream &loggerWOStream(std::wstring_view name) const;

/*!
* \brief WebCFaceサーバーのバージョン情報
Expand Down
13 changes: 13 additions & 0 deletions client/include/webcface/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FuncListener;
class RobotModel;
class Canvas2D;
class Canvas3D;
class Log;

constexpr char field_separator = '.';

Expand Down Expand Up @@ -187,6 +188,14 @@ struct WEBCFACE_DLL Field : public FieldBase {
Canvas3D canvas3D(std::wstring_view field) const;
Canvas2D canvas2D(std::string_view field = "") const;
Canvas2D canvas2D(std::wstring_view field) const;
/*!
* \since ver2.4
*/
Log log(std::string_view field = "") const;
/*!
* \since ver2.4
*/
Log log(std::wstring_view field) const;


std::vector<Value> valueEntries() const;
Expand All @@ -197,6 +206,10 @@ struct WEBCFACE_DLL Field : public FieldBase {
std::vector<Canvas3D> canvas3DEntries() const;
std::vector<Canvas2D> canvas2DEntries() const;
std::vector<Image> imageEntries() const;
/*!
* \since ver2.4
*/
std::vector<Log> logEntries() const;

/*!
* \brief memberがselfならtrue
Expand Down
97 changes: 92 additions & 5 deletions client/include/webcface/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,24 @@ class WEBCFACE_DLL Func : protected Field {
*/
const Func &setImpl(ValType return_type, std::vector<Arg> &&args,
std::function<FuncType> &&func_impl) const;
/*!
* 引数の個数不定バージョン
*
*/
const Func &setImpl(ValType return_type, std::nullopt_t,
std::function<FuncType> &&func_impl) const;
const Func &
setImpl(const std::shared_ptr<internal::FuncInfo> &func_info) const;

/*!
* f_run()を実行し結果をCallHandleに渡す
* f_run()を実行し例外を投げた場合はrejectする
*
*/
template <typename F1>
static void tryRun(F1 &&f_run, const CallHandle &handle) {
static void catchAll(F1 &&f_run, const CallHandle &handle) {
ValAdaptor error;
try {
handle.respond(f_run());
f_run();
return;
} catch (const std::exception &e) {
error = e.what();
Expand All @@ -188,6 +194,14 @@ class WEBCFACE_DLL Func : protected Field {
}
handle.reject(error);
}
/*!
* f_run()を実行し結果をCallHandleに渡す
*
*/
template <typename F1>
static void tryRun(F1 &&f_run, const CallHandle &handle) {
catchAll([&] { handle.respond(f_run()); }, handle);
}

static constexpr std::nullptr_t TraitOk = nullptr;

Expand Down Expand Up @@ -307,6 +321,7 @@ class WEBCFACE_DLL Func : protected Field {
* * ver2.0〜: 自動でrespondされることはないので、
* 関数が受け取ったhandleを別スレッドに渡すなどして、
* ここでセットした関数の終了後にrespond()やreject()することも可能。
* * ver2.4〜: 例外をthrowした場合catchしてreject()する。
*
* \param args 引数の型などの情報
* \param return_type 戻り値の型
Expand All @@ -326,7 +341,7 @@ class WEBCFACE_DLL Func : protected Field {
[args_size, callback = std::move(callback)](
const CallHandle &handle) {
if (handle.assertArgsNum(args_size)) {
callback(handle);
catchAll([&] { callback(handle); }, handle);
}
});
}
Expand All @@ -338,6 +353,7 @@ class WEBCFACE_DLL Func : protected Field {
* * 関数がrespond()もreject()もせず終了した場合自動でrespondされることはないので、
* 関数が受け取ったhandleを別スレッドに渡すなどして、
* ここでセットした関数の終了後にrespond()やreject()することも可能。
* * ver2.4〜: 例外をthrowした場合catchしてreject()する。
*
* \param args 引数の型などの情報
* \param return_type 戻り値の型
Expand All @@ -360,7 +376,69 @@ class WEBCFACE_DLL Func : protected Field {
std::move(callback))](const CallHandle &handle) {
if (handle.assertArgsNum(args_size)) {
std::thread([callback, handle] {
callback->operator()(handle);
catchAll([&] { callback->operator()(handle); }, handle);
}).detach();
}
});
}
/*!
* \brief 引数にCallHandleを取る関数を登録する
* \since ver2.4
*
* * 自動でrespondされることはないので、
* 関数が受け取ったhandleを別スレッドに渡すなどして、
* ここでセットした関数の終了後にrespond()やreject()することも可能。
* * setArgs(), setReturnType() で引数の個数や型と戻り値の型を指定する。
* 指定しない場合、引数なし戻り値なしとみなされる。
* * 例外をthrowした場合catchしてreject()する。
*
* \param func セットする関数または関数オブジェクト。
* 引数としてCallHandleを1つ取り、戻り値はvoidで、
* CallHandle::respond() や reject() を通して値を返す
*
*/
template <typename T,
typename std::enable_if_t<
std::is_same_v<std::invoke_result_t<T, CallHandle>, void>,
std::nullptr_t> = nullptr>
const Func &set(T callback) const {
return setImpl(ValType::none_, std::nullopt,
[base = *this, callback = std::move(callback)](
const CallHandle &handle) {
if (handle.assertArgsNum(base.args().size())) {
catchAll([&] { callback(handle); }, handle);
}
});
}
/*!
* \brief 引数にFuncCallHandleを取り非同期に実行される関数を登録する
* \since ver2.4
*
* * 自動でrespondされることはないので、
* 関数が受け取ったhandleを別スレッドに渡すなどして、
* ここでセットした関数の終了後にrespond()やreject()することも可能。
* * setArgs(), setReturnType() で引数の個数や型と戻り値の型を指定する。
* 指定しない場合、引数なし戻り値なしとみなされる。
* * 例外をthrowした場合catchしてreject()する。
*
* \param func セットする関数または関数オブジェクト。
* 引数としてCallHandleを1つ取り、戻り値はvoidで、
* CallHandle::respond() や reject() を通して値を返す
*
*/
template <typename T,
typename std::enable_if_t<
std::is_same_v<std::invoke_result_t<T, CallHandle>, void>,
std::nullptr_t> = nullptr>
const Func &setAsync(T callback) const {
return setImpl(
ValType::none_, std::nullopt,
[base = *this,
callback = std::make_shared<std::function<void(FuncCallHandle)>>(
std::move(callback))](const CallHandle &handle) {
if (handle.assertArgsNum(base.args().size())) {
std::thread([callback, handle] {
catchAll([&] { callback->operator()(handle); }, handle);
}).detach();
}
});
Expand Down Expand Up @@ -481,6 +559,15 @@ class WEBCFACE_DLL Func : protected Field {
*
*/
const Func &setArgs(const std::vector<Arg> &args) const;
/*!
* \brief 戻り値の型の情報を更新する
* \since ver2.4
*
* set()やsetAsync()で通常の関数をセットした場合戻り値の型は自動的に取得されるので
* setReturnType() を呼ぶ必要はない。
*
*/
const Func &setReturnType(ValType return_type) const;

/*!
* \brief Funcの参照先を比較
Expand Down
Loading
Loading