1 /* Medfield sensor plugins
2 * Copyright (C) 2013 Intel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; version 2.1.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301USA
18 #ifndef BASEPROCESSOR_H
19 #define BASEPROCESSOR_H
22 #include <netinet/in.h>
24 #include <cobject_type.h>
27 #include <sf_common.h>
30 #include <csensor_module.h>
31 #include <cfilter_module.h>
32 #include <csensor_module.h>
33 #include <cprocessor_module.h>
36 #include <linux/input.h>
39 class BaseProcessor: public cprocessor_module {
42 virtual ~BaseProcessor();
44 virtual bool add_input(csensor_module *sensor);
45 virtual bool add_input(cfilter_module *filter);
47 virtual cprocessor_module *create_new(void);
48 virtual void destroy(cprocessor_module *module);
50 virtual const char *name(void);
51 virtual int version(void);
54 virtual bool update_name(char *name);
55 virtual bool update_version(int version);
56 virtual bool update_id(int id);
58 virtual long value(char *port);
59 virtual long value(int id);
61 virtual bool add_callback_func(cmd_reg_t *param);
62 virtual bool remove_callback_func(cmd_reg_t *param);
63 virtual bool check_callback_event(cmd_reg_t *param);
65 virtual long set_cmd(int type , int property , long input_value);
66 virtual int get_property(unsigned int property_level , void *property_struct);
67 virtual int get_property(unsigned int property_level, base_property_struct &result);
70 * @brief get_struct_value Base implementation will call fill_values with struct_type
71 * and copy values from mValues to client response struct
72 * @param struct_type type which should be returned.
73 * @param struct_values values should be put inside this. Type is really base_data_struct *
76 virtual int get_struct_value(unsigned int struct_type , void *struct_values);
80 * @param type which values should be returned. These are defined in sensor headers
81 * @param count this should be filled by implementation and set to amount of values
82 * @param unit unit of values. Must be filled by implementation
83 * @param accuracy accuracy of values. Must be filled by implementation
84 * returned by sensor. Values should be put to mValues array. This function will be
85 * called with mValueMutex held, so its safe to change values in array.
86 * @return true if reading ok, false otherwise
88 virtual bool fill_values(unsigned int type, int &count,
89 data_unit_idx_t &unit, data_accuracy &accuracy) = 0;
92 * @brief process_input_event this function will be called with readed input event.
93 * Base implementation handles events of EV_ABS and EV_REL type and puts values
94 * of these events to mValues array by event->code. This function is called with mValueMutex
96 * @param event event which was readed
98 virtual void process_input_events(const std::vector <input_event *> &events);
101 * @brief start this function will be called by sensor framework when it wants to start
102 * this processor. Base implementation increases mStartCount and only calls
103 * cprocessor::module::start if this is first start. Before cprocessor::module::start
104 * is called enable() will be called (only in case first start).
105 * @return true if processor is started successfully or was previously started, false
108 virtual bool start(void);
112 * @brief stop this function will be called by sensor framework when it wants to start
113 * this processor. Base implementation increases mStartCount and only calls
114 * cprocessor::module::start if this is last stop
115 * @return true if processor is stopped successfully or was previously stopped, false
118 virtual bool stop(void);
121 * @brief enable This function will be called when sensor should be started. Base implementation
122 * tries to find enable file from mSysfsPath path. If it finds it, writes 1 to it.
123 * Base implementation always returns true.
124 * @return true if enabling succeeds otherwise false.
127 virtual bool enable();
130 * @brief disable This function will be called when sensor should be disabled. Base implementation
131 * tries to find enable file from mSysfsPath path. If it finds it, writes 0 to it.
132 * Base implementation always returns true.
133 * @return true if disabling succeeds otherwise false.
135 virtual bool disable();
138 * @brief started this function will be called by sensor framework thread main loop
139 * this static function will call started() implementation of this class
140 * @return value which has been returned by started() function of this class.
142 static void *started(void *);
146 * @brief started this function will be called by started static function. This
147 * function should do sensors data processing. Base implementation reads input events from
148 * mFd file descriptor and feeds them to process_input_event
151 virtual void *started();
154 * @brief find_input_device_by_name Search and open input device for sensor.
155 * Goes through devices under /dev/input and opens device which name matches
156 * to given parameter. Doesn't recurse to subdirs.
157 * @param inputName name returned by EVIOCGNAME ioctl for wanted device
158 * @return true if device found false otherwise
160 bool find_input_device_by_name(const char *inputName);
163 * @brief find_input_device_by_name Search and open input device for sensor.
164 * This function uses sysfs to find device. This function fills mSysfsPath if
166 * @param driver name of the driver for wanted input device
167 * @return true if device found false otherwise
169 const char* find_device_from_udev(const char *driver);
172 * @brief writeToSysfs Writes information to device specific node in sysfs
173 * @param filename filename to write in sysfs. Not including path whics is taken from mSysfsPath
174 * @see find_device_from_udev
175 * @param buffer buffer to write
176 * @param count count of bytes to write
177 * @return false if mSysfsPath is empty or opening of file fails
179 bool writeToSysfs(const char *filename, const char *buffer, int count);
187 /**Sensor driver version*/
190 /**Values read from sensor, fill_values function should use this*/
193 /** Mutex which protects mValues array*/
196 /** How many times this sensor has been started*/
199 /** Callback functions registered*/
200 std::vector <cmd_reg_t> mCallbacks;
202 /** File descriptor associated with sensor*/
205 /** How many input events are expected from sensor*/
206 unsigned int mInputEventCount;
208 /** Path in sysfs to this sensor*/
209 std::string mSysfsPath;
211 /** Supported callback events*/
212 std::vector <int> mSupportedEvents;