Embodiment
In order to understand the application better, the embodiment of the present application is described directly to control flashlamp switch in Android system, be to be understood that, in the application, the operating system of indication can also be other operating systems such as ios, macos, and hardware device can also be camera in electronic equipment, bluetooth, sensor, microphone etc.
Below by specific embodiment, the application is described further.
In the embodiment of the present application, by realizing Kernel Driver (flashlamp driving) at linux kernel space (LinuxKernel layer) and realizing hardware abstraction layer interface at user's space, to provide hardware access interface to more last layer, the application framework layer being Android system provides hardware service.Because the application program Java language of Android system is write, hardware drive program C/C++ language realizes, and Java provides JNI (JavaNativeInterface, Java calls this locality) method call, therefore, in Android system, java application can call hardware abstraction layer interface by JNI.
Please refer to Fig. 2, in the present embodiment, the framework of Android system is divided into five layers.Ground floor 201 is linux kernel driving layer (Linuxkernel), the second layer 202 is hardware abstraction layer (HAL, HardwareAbstractionLayer), third layer 203,204 is Component Gallery layer 203 (Libraries) and virtual machine layer 204 (AndroidRuntime), 4th layer 205 is application framework layer (ApplicationFramework), and layer 5 206 is application layer (Applications).
Based on Fig. 2, please refer to Fig. 3, it illustrates from the analysis of another angle to the framework of Android system.Whole Android system can be divided into hardware, kernel spacing and user's space three parts, its framed contents comprised separately as shown in Figure 3.
In the present embodiment, be divided in third layer by JNI layer, JNI layer is that application framework layer devises a series of interface function, and in the specific implementation of these interface functions, utilizes call back function and hardware abstraction layer to carry out alternately.
It should be noted that, the method of the direct control flashlamp switch that the embodiment of the present application provides is applicable to the Android system of framework shown in Fig. 1 too, the effect increasing hardware abstraction layer in the present embodiment is, for the hardware device without standard Linux kernel-driven layer interface provides the path of access, originally interface poor for readability is changed into readable good interface, is supplied to upper procedure and calls.Namely hardware abstraction layer runs on linux kernel driving layer, under the support of linux kernel driving layer, for application framework layer and JNI layer provide the Interface realization controlled flashlamp.
In Fig. 1 and Fig. 2, the inner frame of each layer is well known to those skilled in the art, and therefore, the application does not translate one by one it and illustrates.
Please refer to Fig. 4, present embodiments provide a kind of method directly controlling flashlamp switch in Android system, comprise step below:
Step 301: application framework layer detects and obtains chained library load instructions.
In a particular embodiment, on the one hand, Android system can load corresponding chained library upon actuation automatically, and therefore, chained library load instructions can be the instruction that Android system sends upon actuation; On the other hand, chained library only just needs when needs call corresponding functional realiey function to load, and therefore, chained library load instructions can be the instruction that Android system sends when detecting and will carry out the calling of functional realiey function.
Step 302: application framework layer loads chained library, and chained library comprises the functional realiey function for controlling flashlamp action.
Functional realiey function is the function for controlling flashlamp action, such as:
led_on
led_off
……
Such as, or when the drive singal of led needs to be provided by another one equipment, cpu chip or camera chip etc., then need first to open this equipment, and then driving LED is luminous.Such advantage is that the pattern of control lamp is more flexible, and such as different colours, different brightness etc. then can be write as minor function:
Led_device_open//open flashlamp (optional, its function opens the said equipment)
Led_device_close//closedown flashlamp (optional, its function opens the said equipment)
led_on
led_off
……
The above-mentioned function for controlling flashlamp action is after definition, and can be kept in .c file, be the definition of all variable sum functions in .c file.
Step 303: application layer obtains the instruction for controlling flashlamp action.This instruction can be the instruction for controlling flashlamp action that user is inputted by the human-computer interaction interface (i.e. application layer) of Android device; Also can be the encoded good strings of commands in application layer, such as, with the serial data that " 0 " and " 1 " represent, wherein, " 0 " represents that flashlamp cuts out, and " 1 " represents that flashlamp is opened.
Based on step 301, instruction for controlling flashlamp action in step 303 also can as chained library load instructions, namely instruction for controlling flashlamp action can be regarded as will carry out calling of functional realiey function, therefore, it should be noted that, the sequence of steps of the method provided in the present embodiment should not be construed the restriction to the application, and in other embodiments, its sequence of steps can carry out suitable conversion according to actual conditions.
Step 304: application layer detects chained library whether loaded, if not, then continues storehouse to be linked loaded, if so, then continues step 305.
Step 305: application layer calls functional realiey function corresponding with the instruction for controlling flashlamp action in chained library.
Application layer can when chained library whole loaded being detected calling function measure for fulfill, or namely to call while detection, or can predetermined time be set, when meeting certain schedule time, just calling function measure for fulfill.
Step 306:Linux kernel-driven layer performs invoked functional realiey function, performs corresponding action to control flashlamp.
In the present embodiment, linux kernel drives in layer and is provided with flashlamp driving, and flashlamp drives and performs invoked functional realiey function, performs corresponding action to control flashlamp.
At present, flashlamp is usual only for the ancillary hardware as camera, only when using camera, just likely flashlamp can be used, therefore, in Android system when using flashlamp, first must calling cameradriver, realizing the control of flashlamp by arranging camera parameter.That is, to the control of flashlamp be the mode indirectly controlled.
There will be the problem of time delay when controlling flashlamp by cameradriver, but for the range of application of current flashlamp, this time delay can not affect normal use.But, along with the development of optical communication (such as visible light communication), when needs carry out information transmission by light, because optical communication is to the requirement of transmission speed and information transmission accuracy, the problem of above-mentioned time delay just highlights gradually, and becomes one of obstacle of optical communication development.
In the present embodiment, drive in layer be independently provided with flashlamp driving at the linux kernel of Android system, when controlling flashlamp, directly can call flashlamp and driving, it is directly control to the control mode of flashlamp.The time delay occurred when controlling flashlamp by cameradriver can be avoided.
The definition of JNI layer has interface function.Application layer calls functional realiey function corresponding with the instruction controlling flashlamp action in chained library according to the interface function of JNI layer, drives the flashlamp of layer to drive perform corresponding functional realiey function for linux kernel.
When described operating system is IOS system, then syscall is localized interface, and can realize JNI layer definition in Android system has the effect of interface function, repeats no more herein.
The interface function of JNI layer defines the corresponding relation of C/C++ function and JAVA function, this interface function adopts JNI method by the C/C++ Function Mapping of hardware abstraction layer on the JAVA function of application layer, to realize the mutual of hardware abstraction layer (adopting C/C++ language) and application layer (employing JAVA language).Led_on is JAVA function, only has the power function that just can be called bottom by the mapping of JNI interface, and it can be mapped to the local function that java_ by name wraps name _ class name _ led_on entirely in JNI layer, then in function, call bottom power function.
Dalvik virtual machine in Android running environment is when calling a member function, if find that this member function is a JNI method, the address so will leaping to it is gone to perform.That is, JNI method directly performs on native operating sys-tern, instead of performed by Dalvik virtual machine interpreter.Therefore, the JNI method means that to be Android application program directly carry out with native operating sys-tern communicates, make communication more efficient by JNI method.
Preferably, JNI layer preserves the address after the instantiation of functional realiey function, so that the direct calling function measure for fulfill of JNI layer.Instantiation refers in OO programming, creates the process of object by class (Class).Such as: in the control procedure of flashlamp, using flashlamp action as class, be object by concrete functional realiey function creation such as unlatching flashlamp, closedown flashlamp.The constructive process of this object, is instantiation.Have the address of a correspondence after this Object Creation is complete, after JNI layer preserves this address, when this functional realiey function of subsequent calls, namely can according to this address fast query to corresponding object, and not need first to retrieve class corresponding to this functional realiey function.
In the present embodiment, three structures below hardware abstraction layer definition has:
Structhw_module_t; // module type: the data structure body must declaring a hal_module_info_sym of each hardware module, first member of this structure must be take hw_module_t as the structure of data.
Structhw_module_methods_t; // modular approach: this structure only provides an interface opening the open function of specific installation, it imports parameter into for " hw_module_t, id " and " w_device_t ", and this function is used for each member of initialization hw_device_t.
Strcuthw_device_t. // device type: must start with this structure for each device data structure body, this structure is the guide line of all devices, is only the data of each equipment oneself after this structure.
In the present embodiment, when defining hardware module type structure, hardware abstraction layer regulation can not directly use hw_module_t structure, need to do a succession, namely a laminar structure is overlapped again outward at this structure, but hw_module_t structure must be first member variable data type of this structure, to facilitate unsteady state operation between the two.Its portion of program code can with reference to as follows:
The effect of definition structure body: together with relevant variable is packaged in function, code encapsulates, to avoid arbitrarily being modified.Structure is a kind of preferred mode, is not necessary.
Structure is by a series of data acquisition having identical type or dissimilar data and form.Structure is used for encapsulating some attributes, parameter equivalence (i.e. data member), to form new type, makes this attribute after encapsulation, parameter equivalence can repeatedly be utilized.
Drive for flashlamp, the structure of its definition can comprise brightness of flash lamp, flashlamp ON/OFF time etc., and brightness value, ON/OFF time are then encapsulated in the structure of respective classes as data member.In addition, for the structure adopting C++ definition, its data member can also be function, not only may be used for the state of description object, the behavior of description object can also be used for, such as, control flashlamp open/close function LED_ON, LED_OFF, LED_DEVICE_OPEN, LED_DEVICE_CLOSE, they are corresponding aforesaid led_on, led_off respectively, led_device_open, led_device_close function.
Please refer to Fig. 5, corresponding to the method directly controlling flashlamp switch in above-mentioned Android system, the present embodiment is also corresponding provides the device directly controlling flashlamp switch in a kind of Android system, comprises loading unit 401, detecting unit 402, call unit 403 and performance element 404.
Loading unit 401 for obtaining chained library load instructions, and loads chained library, and chained library comprises the functional realiey function for controlling flashlamp action.
Detecting unit 402 controls the instruction of flashlamp action for obtaining.
After call unit 403 detects that loading unit 401 has loaded dynamic link library, call functional realiey function corresponding with the instruction controlling flashlamp action in described chained library, or namely call while detection, or can predetermined time be set, when meeting certain schedule time, just call chained library.
Performance element 404, for performing invoked functional realiey function, performs corresponding action to control flashlamp.In a particular embodiment, the framework of Android system comprises application layer, application framework layer, Component Gallery and virtual machine layer, linux kernel drives layer.Linux kernel drives in layer and is provided with flashlamp driving, and performance element 404 drives the flashlamp in layer to drive the invoked functional realiey function of execution for controlling linux kernel, performs corresponding action to control flashlamp.
The framework of Android system also comprises JNI layer, and the definition of JNI layer has interface function.Loading unit 401 for control application framework layer detect get chained library load instructions after, load chained library.Call unit 403 calls functional realiey function corresponding with the instruction controlling flashlamp action in chained library for controlling application program layer according to the interface function of JNI layer, drives the flashlamp of layer to drive perform corresponding functional realiey function for linux kernel.
Further, JNI layer preserves the address after the instantiation of functional realiey function.
Preferably, the framework of Android system also comprises hardware abstraction layer, and hardware abstraction layer runs on linux kernel and drives on layer, under the support of linux kernel driving layer, for application framework layer and JNI layer provide the Interface realization controlled flashlamp.
When operating system is IOS system, it is adaptive that IOS system also comprises Library storehouse, can realize the effect of hardware abstraction layer in the framework of roughly the same Android system, repeat no more herein.
Directly control in the Android system that the embodiment of the present application provides in the method and apparatus of flashlamp switch, first after detection gets chained library load instructions, load chained library; After obtaining the instruction for controlling flashlamp action, call functional realiey function corresponding with this instruction in chained library; Perform invoked functional realiey function afterwards, perform corresponding action to control flashlamp, thus realize the direct control to flashlamp switch.
Directly control all right expanded application of method and apparatus of flashlamp switch in the Android system that the embodiment of the present application provides to WP operating system, concrete realization roughly the same, repeats no more.
It will be appreciated by those skilled in the art that, in above-mentioned embodiment, all or part of step of various method can be carried out instruction related hardware by program and completes, this program can be stored in a computer-readable recording medium, and storage medium can comprise: ROM (read-only memory), random access memory, disk or CD etc.
Above content is the further description done the application in conjunction with concrete embodiment, can not assert that the concrete enforcement of the application is confined to these explanations.For the application person of an ordinary skill in the technical field, under the prerequisite not departing from the present application design, some simple deduction or replace can also be made.