Skip to content

Commit 9cb8202

Browse files
authored
[PlatformChannel] Minor refactoring and implementation of SystemSound.play() (#84)
Signed-off-by: Pawel Wasowski <[email protected]>
1 parent af68221 commit 9cb8202

File tree

2 files changed

+61
-46
lines changed

2 files changed

+61
-46
lines changed

shell/platform/tizen/BUILD.gn

+2-16
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ config("tizen_rootstrap_include_dirs") {
7979
template("embedder_for_profile") {
8080
forward_variables_from(invoker, [ "use_evas_gl_renderer" ])
8181

82-
profile = target_name
83-
8482
if (!defined(use_evas_gl_renderer)) {
8583
use_evas_gl_renderer = false
8684
}
@@ -110,6 +108,7 @@ template("embedder_for_profile") {
110108
libs = [
111109
"base-utils-i18n",
112110
"capi-appfw-application",
111+
"capi-base-common",
113112
"capi-system-info",
114113
"capi-system-system-settings",
115114
"dlog",
@@ -119,26 +118,13 @@ template("embedder_for_profile") {
119118
"eina",
120119
"evas",
121120
"EGL",
121+
"feedback",
122122
"GLESv2",
123123
"tbm",
124124
"tdm-client",
125125
"wayland-client",
126126
]
127127

128-
if (profile == "mobile") {
129-
libs += [
130-
"capi-base-common",
131-
"feedback",
132-
]
133-
}
134-
135-
if (profile == "wearable") {
136-
libs += [
137-
"capi-base-common",
138-
"feedback",
139-
]
140-
}
141-
142128
defines = invoker.defines
143129

144130
if (use_evas_gl_renderer) {

shell/platform/tizen/channels/platform_channel.cc

+59-30
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ class FeedbackManager {
4040
kUnknownError
4141
};
4242

43+
enum class FeedbackPattern {
44+
kClick = FEEDBACK_PATTERN_TAP,
45+
kAlert = FEEDBACK_PATTERN_GENERAL,
46+
kSip = FEEDBACK_PATTERN_SIP
47+
};
48+
49+
enum class FeedbackType {
50+
kVibration = FEEDBACK_TYPE_VIBRATION,
51+
kSound = FEEDBACK_TYPE_SOUND
52+
};
53+
4354
static std::string GetVibrateVariantName(const char* haptic_feedback_type) {
4455
FT_LOGD(
4556
"Enter FeedbackManager::GetVibrateVariantName(): haptic_feedback_type: "
@@ -60,30 +71,32 @@ class FeedbackManager {
6071
std::string{haptic_feedback_type + kPrefixToRemoveLen};
6172
}
6273

63-
static std::string GetErrorMessage(const std::string& method_name,
64-
ResultCode result_code) {
74+
static std::string GetErrorMessage(ResultCode result_code,
75+
const std::string& method_name,
76+
const std::string& args = "") {
6577
FT_LOGD(
66-
"Enter FeedbackManager::GetErrorMessage(): method_name: (%s), "
67-
"result_code: [%d]",
68-
method_name.c_str(), static_cast<int>(result_code));
78+
"Enter FeedbackManager::GetErrorMessage(): result_code: [%d], "
79+
"method_name: (%s), args: (%s)",
80+
static_cast<int>(result_code), method_name.c_str(), args.c_str());
81+
82+
const auto method_name_with_args = method_name + "(" + args + ")";
6983

7084
switch (result_code) {
7185
case ResultCode::kNotSupportedError:
72-
return method_name + "() is not supported";
86+
return method_name_with_args + " is not supported";
7387
case ResultCode::kPermissionDeniedError:
74-
return std::string{"No permission to run "} + method_name +
75-
"(). Add "
88+
return std::string{"No permission to run "} + method_name_with_args +
89+
". Add "
7690
"\"http://tizen.org/privilege/feedback\" privilege to "
7791
"tizen-manifest.xml "
7892
"to use this method";
7993
case ResultCode::kUnknownError:
8094
default:
81-
return std::string{"An unknown error on "} + method_name + "() call";
95+
return std::string{"An unknown error on "} + method_name_with_args +
96+
" call";
8297
}
8398
}
8499

85-
#if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
86-
87100
static FeedbackManager& GetInstance() {
88101
FT_LOGD("Enter FeedbackManager::GetInstance()");
89102

@@ -94,17 +107,18 @@ class FeedbackManager {
94107
FeedbackManager(const FeedbackManager&) = delete;
95108
FeedbackManager& operator=(const FeedbackManager&) = delete;
96109

97-
ResultCode Vibrate() {
98-
FT_LOGD("Enter FeedbackManager::Vibrate()");
110+
ResultCode Play(FeedbackType type, FeedbackPattern pattern) {
111+
FT_LOGD("Enter FeedbackManager::Play(): type: [%d], pattern: [%d]",
112+
static_cast<int>(type), static_cast<int>(pattern));
99113

100114
if (ResultCode::kOk != initialization_status_) {
101-
FT_LOGE("Cannot run Vibrate(): initialization_status_: [%d]",
115+
FT_LOGE("Cannot run Play(): initialization_status_: [%d]",
102116
static_cast<int>(initialization_status_));
103117
return initialization_status_;
104118
}
105119

106-
auto ret =
107-
feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP);
120+
auto ret = feedback_play_type(static_cast<feedback_type_e>(type),
121+
static_cast<feedback_pattern_e>(pattern));
108122
if (FEEDBACK_ERROR_NONE == ret) {
109123
FT_LOGD("feedback_play_type() succeeded");
110124
return ResultCode::kOk;
@@ -163,8 +177,6 @@ class FeedbackManager {
163177
}
164178

165179
ResultCode initialization_status_ = ResultCode::kUnknownError;
166-
167-
#endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
168180
};
169181

170182
} // namespace
@@ -178,13 +190,32 @@ void PlatformChannel::HandleMethodCall(
178190
ui_app_exit();
179191
result->Success();
180192
} else if (method == "SystemSound.play") {
181-
result->NotImplemented();
193+
FT_LOGD("SystemSound.play() call received");
194+
195+
const std::string pattern_str = call.arguments()[0].GetString();
196+
197+
const FeedbackManager::FeedbackPattern pattern =
198+
(pattern_str == "SystemSoundType.click")
199+
? FeedbackManager::FeedbackPattern::kClick
200+
: FeedbackManager::FeedbackPattern::kAlert;
201+
202+
auto ret = FeedbackManager::GetInstance().Play(
203+
FeedbackManager::FeedbackType::kSound, pattern);
204+
if (FeedbackManager::ResultCode::kOk == ret) {
205+
result->Success();
206+
return;
207+
}
208+
209+
const auto error_cause =
210+
FeedbackManager::GetErrorMessage(ret, "SystemSound.play", pattern_str);
211+
const std::string error_message = "Could not play sound";
212+
FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
213+
214+
result->Error(error_cause, error_message);
215+
182216
} else if (method == "HapticFeedback.vibrate") {
183217
FT_LOGD("HapticFeedback.vibrate() call received");
184218

185-
const std::string error_message = "Could not vibrate";
186-
187-
#if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
188219
/*
189220
* We use a single type of vibration (FEEDBACK_PATTERN_SIP) to implement
190221
* HapticFeedback's vibrate, lightImpact, mediumImpact, heavyImpact
@@ -194,7 +225,9 @@ void PlatformChannel::HandleMethodCall(
194225
* calls.
195226
*/
196227

197-
auto ret = FeedbackManager::GetInstance().Vibrate();
228+
auto ret = FeedbackManager::GetInstance().Play(
229+
FeedbackManager::FeedbackType::kVibration,
230+
FeedbackManager::FeedbackPattern::kSip);
198231
if (FeedbackManager::ResultCode::kOk == ret) {
199232
result->Success();
200233
return;
@@ -203,14 +236,10 @@ void PlatformChannel::HandleMethodCall(
203236
const auto vibrate_variant_name =
204237
FeedbackManager::GetVibrateVariantName(call.arguments()[0].GetString());
205238
const auto error_cause =
206-
FeedbackManager::GetErrorMessage(vibrate_variant_name, ret);
239+
FeedbackManager::GetErrorMessage(ret, vibrate_variant_name);
240+
const std::string error_message = "Could not vibrate";
241+
207242
FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
208-
#else
209-
const auto vibrate_variant_name =
210-
FeedbackManager::GetVibrateVariantName(call.arguments()[0].GetString());
211-
const auto error_cause = FeedbackManager::GetErrorMessage(
212-
vibrate_variant_name, FeedbackManager::ResultCode::kNotSupportedError);
213-
#endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
214243

215244
result->Error(error_cause, error_message);
216245
} else if (method == "Clipboard.getData") {

0 commit comments

Comments
 (0)