• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
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 /* Vibra implementation */
18 
19 #include "sles_allinclusive.h"
20 
21 
IVibra_Vibrate(SLVibraItf self,SLboolean vibrate)22 static SLresult IVibra_Vibrate(SLVibraItf self, SLboolean vibrate)
23 {
24     SL_ENTER_INTERFACE
25 
26     IVibra *thiz = (IVibra *) self;
27     interface_lock_poke(thiz);
28     thiz->mVibrate = SL_BOOLEAN_FALSE != vibrate; // normalize
29     interface_unlock_poke(thiz);
30     result = SL_RESULT_SUCCESS;
31 
32     SL_LEAVE_INTERFACE
33 }
34 
35 
IVibra_IsVibrating(SLVibraItf self,SLboolean * pVibrating)36 static SLresult IVibra_IsVibrating(SLVibraItf self, SLboolean *pVibrating)
37 {
38     SL_ENTER_INTERFACE
39 
40     if (NULL == pVibrating) {
41         result = SL_RESULT_PARAMETER_INVALID;
42     } else {
43         IVibra *thiz = (IVibra *) self;
44         interface_lock_peek(thiz);
45         SLboolean vibrate = thiz->mVibrate;
46         interface_unlock_peek(thiz);
47         *pVibrating = vibrate;
48         result = SL_RESULT_SUCCESS;
49     }
50 
51     SL_LEAVE_INTERFACE
52 }
53 
54 
IVibra_SetFrequency(SLVibraItf self,SLmilliHertz frequency)55 static SLresult IVibra_SetFrequency(SLVibraItf self, SLmilliHertz frequency)
56 {
57     SL_ENTER_INTERFACE
58 
59     const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor;
60     if (!d->supportsFrequency) {
61         result = SL_RESULT_PRECONDITIONS_VIOLATED;
62     } else if (!(d->minFrequency <= frequency && frequency <= d->maxFrequency)) {
63         result = SL_RESULT_PARAMETER_INVALID;
64     } else {
65         IVibra *thiz = (IVibra *) self;
66         interface_lock_poke(thiz);
67         thiz->mFrequency = frequency;
68         interface_unlock_poke(thiz);
69         result = SL_RESULT_SUCCESS;
70     }
71 
72     SL_LEAVE_INTERFACE
73 }
74 
75 
IVibra_GetFrequency(SLVibraItf self,SLmilliHertz * pFrequency)76 static SLresult IVibra_GetFrequency(SLVibraItf self, SLmilliHertz *pFrequency)
77 {
78     SL_ENTER_INTERFACE
79 
80     if (NULL == pFrequency) {
81         result = SL_RESULT_PARAMETER_INVALID;
82     } else {
83         IVibra *thiz = (IVibra *) self;
84         interface_lock_peek(thiz);
85         SLmilliHertz frequency = thiz->mFrequency;
86         interface_unlock_peek(thiz);
87         *pFrequency = frequency;
88         result = SL_RESULT_SUCCESS;
89     }
90 
91     SL_LEAVE_INTERFACE
92 }
93 
94 
IVibra_SetIntensity(SLVibraItf self,SLpermille intensity)95 static SLresult IVibra_SetIntensity(SLVibraItf self, SLpermille intensity)
96 {
97     SL_ENTER_INTERFACE
98 
99     const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor;
100     if (!d->supportsIntensity) {
101         result = SL_RESULT_PRECONDITIONS_VIOLATED;
102     } else if (!(0 <= intensity && intensity <= 1000)) {
103         result = SL_RESULT_PARAMETER_INVALID;
104     } else {
105         IVibra *thiz = (IVibra *) self;
106         interface_lock_poke(thiz);
107         thiz->mIntensity = intensity;
108         interface_unlock_poke(thiz);
109         result = SL_RESULT_SUCCESS;
110     }
111 
112     SL_LEAVE_INTERFACE
113 }
114 
115 
IVibra_GetIntensity(SLVibraItf self,SLpermille * pIntensity)116 static SLresult IVibra_GetIntensity(SLVibraItf self, SLpermille *pIntensity)
117 {
118     SL_ENTER_INTERFACE
119 
120     if (NULL == pIntensity) {
121         result = SL_RESULT_PARAMETER_INVALID;
122     } else {
123         const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor;
124         if (!d->supportsIntensity) {
125             result = SL_RESULT_PRECONDITIONS_VIOLATED;
126         } else {
127             IVibra *thiz = (IVibra *) self;
128             interface_lock_peek(thiz);
129             SLpermille intensity = thiz->mIntensity;
130             interface_unlock_peek(thiz);
131             *pIntensity = intensity;
132             result = SL_RESULT_SUCCESS;
133         }
134     }
135 
136     SL_LEAVE_INTERFACE
137 }
138 
139 
140 static const struct SLVibraItf_ IVibra_Itf = {
141     IVibra_Vibrate,
142     IVibra_IsVibrating,
143     IVibra_SetFrequency,
144     IVibra_GetFrequency,
145     IVibra_SetIntensity,
146     IVibra_GetIntensity
147 };
148 
IVibra_init(void * self)149 void IVibra_init(void *self)
150 {
151     IVibra *thiz = (IVibra *) self;
152     thiz->mItf = &IVibra_Itf;
153     thiz->mVibrate = SL_BOOLEAN_FALSE;
154     // next 2 values are undefined per spec
155     thiz->mFrequency = Vibra_id_descriptors[0].descriptor->minFrequency;
156     thiz->mIntensity = 1000;
157 }
158