Merge "Add support for FontClient PreCache in candidate process" into devel/master
[platform/core/uifw/dali-adaptor.git] / plugins / dali-feedback.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #define LOG_TAG "DALI_FEEDBACK"
19
20 // CLASS HEADER
21 #include "dali-feedback.h"
22
23 // EXTERNAL INCLUDES
24 #include <feedback.h>
25 #include <mm_sound.h>
26 #include <mm_sound_private.h>
27 #include <fstream>
28 #include <iostream>
29
30 #include <dlog.h>
31
32 #define DEBUG_PRINTF(fmt, arg...) LOGD(" " fmt, ##arg)
33
34 using std::string;
35 using namespace Dali;
36
37 // The plugin factories
38 extern "C" DALI_ADAPTOR_API Dali::FeedbackPlugin* CreateFeedbackPlugin(void)
39 {
40   return new Dali::Plugin::DaliFeedback;
41 }
42
43 namespace Dali
44 {
45 namespace Plugin
46 {
47 DaliFeedback::DaliFeedback()
48 {
49   feedback_initialize();
50 }
51
52 DaliFeedback::~DaliFeedback()
53 {
54   feedback_deinitialize();
55 }
56
57 void DaliFeedback::PlayHaptic(const std::string& filePath)
58 {
59 }
60
61 void DaliFeedback::PlayHapticMonotone(unsigned int duration)
62 {
63 }
64
65 void DaliFeedback::StopHaptic()
66 {
67 }
68
69 int DaliFeedback::PlaySound(const std::string& fileName)
70 {
71   int handle    = -1;
72   int errorCode = mm_sound_play_keysound(fileName.c_str(), VOLUME_TYPE_SYSTEM & VOLUME_GAIN_TOUCH);
73   if(errorCode < 0)
74   {
75     DEBUG_PRINTF("PlaySound() %s failed with error code = %d\n", fileName.c_str(), errorCode);
76   }
77
78   return handle;
79 }
80
81 void DaliFeedback::StopSound(int handle)
82 {
83   int errorCode = mm_sound_stop_keysound(NULL);
84   if(errorCode < 0)
85   {
86     DEBUG_PRINTF("StopSound() handle = %d failed with error code = %d\n", handle, errorCode);
87   }
88   else
89   {
90     DEBUG_PRINTF("stop handle %d success\n", handle);
91   }
92 }
93
94 void DaliFeedback::PlayFeedbackPattern(int type, int pattern)
95 {
96   int errorCode = feedback_play_type(static_cast<feedback_type_e>(type), static_cast<feedback_pattern_e>(pattern));
97   if(errorCode != 0)
98   {
99     DEBUG_PRINTF("DaliFeedback::PlayFeedbackPattern() with type = %d, pattern = %d returned with error = %d\n", (int)type, (int)pattern, errorCode);
100   }
101 }
102
103 } // namespace Plugin
104
105 } // namespace Dali