Embodiment
Describe technical scheme of the present invention with reference to the accompanying drawings in detail.
As shown in Figure 1, in order to realize the foregoing invention purpose, the invention provides the distributed apparatus Redirectional system in a kind of graphic terminal environment, mainly comprise virtual drive module, service agent module and terminal proxy module, passage by " application → virtual drive module → service agent module → terminal proxy module → terminal equipment driving → terminal equipment ", the access logic of using equipment is reflected on the terminal equipment, and return according to the contrary of former passage, realize device redirection, the equipment that satisfies in the multiple users network environment is supported needs.
More particularly, the device redirection system comprises virtual drive module, supports registration/cancellation, listening port and device file operation-interface, based on redirected agreement, and the data communication between realization and service agent module.Wherein, virtual drive module comprises again:
The registration interface unit, the primary and secondary device number of registration is consistent with the device number of system standard equipment, according to the equipment needs of reality, registers a plurality of secondary devices, satisfies the autgmentability requirement.Registration interface provides the support of kernel spacing multithreading, and the port monitor function is provided in new thread.
The port monitoring unit is set up the virtual service broker's of being driven into redirected passage, finishes the foundation and the monitoring of communication port.Virtual driving receives that the service broker sends lands session identification sid and the corresponding relation between record sid and communication port.
Device file operation-interface unit, according to equipment open, the process of the control of equipment I/O, equipment read-write and device shutdown supports the standard device access interface.The interface definition conformance with standard drives design principle, satisfies the compatible requirement with standard device.
Equipment is opened interface unit, finishes the conversion that application process identifies pid and session identification sid with the service broker, judges according to the result to start the user conversation of using.To open logical description and send to the service broker, and acceptance is from service broker's feedback.
Equipment I/O control interface unit sends to the service broker with the description of I/O control logic, and accepts the feedback from the service broker.
Equipment is read interface unit, will read logical description and send to the service broker, and acceptance comprises the facility information that the equipment of reading obtains from service broker's feedback in the feedback.
Equipment is write interface unit, will write logical description and send to the service broker, describes to comprise the data of writing to equipment, and accepts service broker's feedback.
The device shutdown interface unit will be closed logical description and be sent to the service broker, and accept the feedback from the service broker.
The device redirection system also comprises service agent module, is used to realize that the multi-user lands support, monitors the login user situation, judges to start the user who uses; Realize communication interface and protocol description between service agent module and virtual drive module and service agent module and terminal proxy module.Wherein, service agent module comprises:
The session-context that a plurality of terminal uses land is monitored and managed in the multiple line distance management unit.The shared drive unit, the recording user session identification.
" service agent module-virtual drive module " communications interface unit, interactive user session identification and application process sign make up the device redirection passage between service agent module and virtual drive module, realize the transmission of device access logic between the two pellucidly.
" service agent module-terminal proxy module " communications interface unit makes up the device redirection passage between service agent module and terminal proxy module, realizes the transmission of device access logic between the two pellucidly.
The device redirection system also comprises the terminal proxy module, sends the user and lands request, and communication interface and protocol description between realization and service agent module, the analyzing device access logic is the operating terminal local device then.Wherein, the terminal proxy module comprises:
" terminal proxy module-service agent module " communications interface unit sends the request of landing, and makes up the device redirection passage between terminal proxy module and service agent module.
The access logic resolution unit analyzes different access logics and describes.
The device access unit, according to analysis result access terminal local device, the equipment of finishing the execution of terminal use's application program started is opened, I/O controls, equipment is read and write and shutoff operation, and the feedback of device access is returned the service broker.
Below in conjunction with accompanying drawing, at first embodiments of the present invention are made function and describe, then in conjunction with the redirected developing example of audio frequency apparatus, describe the information interactive process of device redirection in detail.
The design of virtual drive module and realization:
In graphic terminal was used, the virtual driving on the application server was by kernel or modular manner operation, and monitoring is from Terminal Service agency's request.If user's off-duty voice applications, the communications status between then virtual driving and Terminal Service agency is constant; If the voice applications on user's runtime server, then access logic is carried out according to the description of using.
The realization of the registration/cancellation of virtual driving is followed standard and is driven design, interface is init_module () and cleanup_module (), the primary and secondary device number of registration is consistent with the device number of system standard equipment, finish by devfs_register_dev () and devfs_mk_dir () function, satisfy server end device description coherence request.
Virtual driving of the present invention starts watcher thread by kernel_thread (), the communication port between monitoring and the service broker.Snoop procedure as shown in the figure.Watcher thread is waited for the connection request from the service broker, so that obtain the session information that lands or nullify.Service broker's request form is " conversation description+session identification ".Landing and nullify session is represented by " CN " and " DS " respectively.Session identification sid is obtained in virtual driving, to landing session the corresponding relation between sid and communication port is recorded in the system list, for future use; To nullifying session, itself and corresponding communication port information are deleted from tabulation.
Application to the operation of equipment according to equipment open, the order of equipment I/O control, equipment read-write and device shutdown carries out.Application realizes by device file operation-interface file_operations organization definition operating in the driving of equipment.Virtual driving mainly by the passage of " application → virtual driving → service broker → terminal agency → terminal equipment driving → terminal equipment ", is reflected to the access logic of using equipment on the terminal equipment, and returns according to the contrary of former passage.It should be noted that every kind of access logic all comprises command code and operand, describes operational order and operand respectively.Above-mentioned communication process has the transparency, and this transparency remains on above-mentioned communication process all the time always, and middle virtual driving and each agency also are indifferent to the details of order.Analytical work is carried out at last the terminal agency's.Terminal proxy resolution command code and operand, and finish the I/O control operation of real equipment by the calling interface of standard according to the result.
The present invention opens equipment interface by what virtual driving was registered in kernel, obtain the process identification (PID) pid of voice applications, by the data communication between virtual driving and Terminal Service agency, pid is reached the service broker, and the startup user conversation of acquisition voice applications identifies sid on the agency, and return driving.Legal sid returns and shows that voice applications carried out by the legal terminal login user, search sid and communication port relation contrast tabulation, the communication port of acquisition and corresponding session has been set up the corresponding relation between user and application this moment, the separation of the different sessions process data after serving.Process as shown in Figure 2.Simultaneously, return the information of normally opening to application.
Be applied in after the equipment of opening, need, the I/O attribute of equipment is provided with, obtains and revises by equipment I/O control interface ioctl operation.I/O control is complicated operations comparatively in the device driver, and interface definition comprises command word (command code) and parameter (operand).Be applied among the present invention when carrying out equipment I/O control operation, the control command word that virtual driving is just used from the system call interfaces program that is applied is also analyzed, obtaining action type at command code by macrodefinition _ IOC_DIR () is NONE, OUT, IN or the order of INOUT type, correspondence is not with parameter respectively, parameter is set, read parameter, four types of consultation parameters, call corresponding processing procedure then respectively, utilize protocol interaction partly to finish its function, the I/O control of using equipment is redirected on the terminal equipment.
In operation of equipment, read-write operation is that the most frequent operation takes place, and generally all is in the circle logic of application program.Read-write operation has two distinguishing features: the one, and operand part is huge, and what often transmit is buffer pointer; The 2nd, the state of read-write need return, and the factor that influences return state is more.The present invention is when the communication protocol of design read-write operation, and operating data buffering area part often adopts the random length mode, and is equipped with the size that length byte is described actual buffering area.Return state places one's entire reliance upon to the feedback of terminal equipment practical operation.
The redirected agreement of closing device operation of the present invention by defining between virtual drive module and service agent module passes to the service broker pellucidly.
The design of service agent module and realization:
Among the present invention, service agent module comprises that mainly information sends and receiving interface.The information transmission interface is realized receiving various requests from virtual driving, and is repackaged into service---and the protocol format (mainly being the syllable sequence difference) between the terminal agency is forwarded to Client Agent with request; The message pick-up interface receives various replying from Client Agent, and is repackaged into the protocol format (mainly being that syllable sequence is different) between service broker and virtual driving, mails to virtual driving.
The design of terminal proxy module and realization
Among the present invention, Client Agent partly provides the protocol interaction part corresponding to the service agent module transmitting-receiving.In addition, need describe according to the access logic of service broker's notice, design realizes the visit to local device.The operation of equipment interface of standard is adopted in the visit of local device, and the feedback of operating result need return to the Terminal Service agency.
4, design of communication protocol and realization, promptly be redirected the design and the realization of agreement:
Comprise three parts: device discovery, device description and device access.
Device discovery is mainly realized the discovery of terminal existing equipment, notice and feedback.Some equipment just exists at the beginning of terminal powers up and comes into force, such as keyboard/mouse, three cards (video card, network interface card and sound card) etc.These equipment will notification service when the user lands Terminal Service agency and at the service end record; And some equipment is supported plug-and-play feature, and USB device is exactly like this.Suchlike equipment may be before or after the user lands be connected with terminal and notifies Terminal Service.Above-mentioned which kind of situation no matter, agreement all needs to describe device discovery messages to Terminal Service, and the feedback of Terminal Service described is back to the terminal agency.
Device description, in a single day equipment be found, and just needs terminal that the specific descriptions information of equipment can be provided to service end.Descriptor should comprise device type, device descriptor, capacity of equipment description at least.
Terminal equipment roughly is divided into two classes: character device and block device.The I/O of character device is a unit with the byte, and the I/O of block device is a unit with record block or " sector ".By the development of many decades, the boundary between block device and the character device is fuzzy, but is continuing to use such division.
Device descriptor mainly is the concrete equipment that is used on the distinguishing terminal, can directly adopt the terminal equipment descriptor, can use dsp, mixer etc. such as audio frequency apparatus, and disk unit can be used hda, sda etc.; Also can adopt the primary and secondary device number to describe, the distribution of primary and secondary device number is described according to the primary and secondary device number of the equipment of terminal operating system, is respectively 14/3 and 14/0 etc. such as the primary and secondary device number of the dsp of audio frequency apparatus and mixer.
It is the equipment associated ancillary information that capacity of equipment is described, and depends on concrete equipment, the current I/O ability of description equipment, user mode etc.It also is the needs of serving terminal equipment adaptive ability support from now on that capacity of equipment is described.
Device access, main in patent application what introduce is the realization of this part, describes the opening of equipment, I/O control, reads and writes and close logic.
Among the present invention, the communication protocol between proxy module comprises that the request and the terminal of serving terminal arrive response two parts of service.Be described below respectively:
1) the request msg packet format is as shown in table 1:
The virtual data packet format that is driven into terminal of table 1
Length |
Operation code |
The parameter word segment table |
2 bytes |
1 byte |
Variable-length |
Wherein each Field Definition is as follows:
Length field: whole length of data package.
Do not have the poll item in the definition of operating in the operations structure.The select that the poll operation is used for system calls, and is specifically designed to the contradiction between the peripheral hardware operation of handling high-speed CPU and low speed.The essence of Select system call is that the sleep of single process in the system is waited for that becoming multiobject sleep waits for, improves the operational efficiency of whole system.If the Terminal Service process transfer select system call, it is actual that what wait for should be the operation of returning from remote terminal, depend on two factors: wait process of reading on the terminal and terminal are sent to virtual driving with reading result through network.Therefore poll call actual should be corresponding to for providing the socket of transfer of data to call between virtual device driver and the terminal.Therefore do not need regulation that poll is operated the operation code that is sent to terminal in table 2, the corresponding socket of a poll process only need directly call to(for) the poll operation gets final product.
Parameter field: the parameter format of regulation corresponding operating code, concrete form is as shown in table 3.Wherein parameter type is stipulated the form of data in this parameter, as 16 integers, 32 integers, byte stream etc.Have only when the supplemental characteristic type is byte stream, parameter length field is just arranged in the argument structure.Parameter value field subsequently is actual parameter value.
Table 3 parameter format
Parameter type |
Parameter length |
Parameter value |
1 byte |
2 bytes |
Variable-length |
2) the response data packet format is as shown in table 4:
Table 4 terminal equipment operation response
The success mark |
Length |
The parameter word segment table |
1 byte |
2 bytes |
Variable-length |
Wherein the meaning of each field is as follows:
The success mark: expression is by using the execution result of access request on the terminal physical device of initiating, and value is that 1 expression runs succeeded, otherwise expression makes mistakes in the process of implementation.
Length field: the total length of the data of expression back.
Parameter field: it is as shown in the table for concrete form.Return value or optional parameters for this operation.
As shown in Figure 3, reorientation method of the present invention may further comprise the steps:
Step 100 loads virtual driving;
Step 110 starts the service broker, and foundation is connected with virtual driving;
Step 120, user's telnet (at this moment, by the service broker, the relation in virtual driving between recording conversation sign sid and communication port);
Step 130, the user starts application in the terminal applies environment;
Step 140 is used and is sent the device access request to virtual driving, the forming device access logic;
Step 150, the device access logic is passed to the service broker by virtual driving;
Step 150, the device access logic is passed to the service broker by virtual driving;
Step 160, the device access logic is passed to the terminal agency by the service broker;
Step 170, terminal proxy resolution access logic, and realize the local device visit;
The feedback of device access is returned by above-mentioned route;
As shown in Figure 4, the realization flow of virtual driving may further comprise the steps:
Step 200, application system is called;
Step 210, the kind of judgement system call is called if system call is open, then carries out next step, calls if system call is ioctl, and then execution in step 230, if for other calls, then execution in step 240; Wherein, system call comprises that open calls, and release calls, and read calls, and write calls, and ioctl calls, and poll calls.
Step 220 is obtained the port information with corresponding session communication, execution in step 240;
Step 230 is judged the ioctl type, and is handled accordingly execution in step 240;
Step 240, protocol interaction;
Step 250 is called and is returned.
In step 240, as shown in Figure 5,1-3 are the access logic mapping, and 4-6 are the visit feedback.
In the graphic terminal environment, multimedia application is an important use.In order to satisfy support to sound application, in terminal network, support audio frequency apparatus better, be the emphasis of the device redirection studied of the present invention.
Describe in conjunction with the foregoing invention implementation process, being redirected with audio frequency apparatus is embodiment, describes the specific implementation process of device redirection of the present invention.Along with the development of sound device hardware and enriching of application, voice applications needs sound card can support MIDI equipment, mixer apparatus etc.Wherein, mixer apparatus/dev/mixer is used widely in most voice applications as the volume adjustment means.The present invention has autgmentability preferably, can support plurality of devices to describe.The realization principle and the conventional audio equipment of mixer are identical, below the main embodiment of introducing at conventional audio equipment/dev/dsp.
1) user lands and registers
Virtual driving at first is loaded in the kernel with modular manner, in the registration process of kernel as mentioned above.Register its enable port watcher thread that finishes, monitor information (this moment, the service broker started as yet) from the service broker.Start the service broker, monitor self terminal agency's information.The terminal agency initiates the user and lands request, and foundation is connected with the service broker's.To each user who newly lands, service broker's distributing user session identification sid, the maintenance of startup thread is connected and data communication with the user's.Sid with the user in thread passes to virtual driving by solicited message.Virtual driving receives the sid that the service broker is transmitted, and the relation information of record sid and communication port finishes that the user lands and registration process.
2) application start process
The terminal use is by the audio application in the graphic interface startup service.Voice applications is at first by open order, and operating audio device file descriptor/dev/dsp carries out the opening operation of audio frequency apparatus, and this operation information is opened interface dev_open by the device file that kernel passes to virtual driving.In this interface,, the application process sign pid that gets access to is passed to the service broker according to said process.The service broker obtains pid, by visit/proc file system, obtains session identification sid, and virtual driving is given in passback.Virtual driving obtains the communication port of the session communication corresponding with the voice applications process by the sid of record and the relation between communication port.
3) application is to the visit of sound card
The I/O control ratio of sound card is abundanter, can be provided with and the information of obtaining many relevant sound card equipment attributes, and be example with the buffer information, sound card can be provided with and obtain the size of buffering area, and this corresponds respectively to above-mentioned OUT and the order of IN type.Interface definition to the setting of sound card buffering area in the application is:
ioctl(int?audio_fd,int?cmd,char*blocksize)
Wherein, audio_fd is the sound card equipment document number, and cmd is a command word, is SNDCTL_DSP_GETBLKSIZE at this, represents that this order need obtain buffer size, and blocksize is the buffer size of returning.This command mapping is to virtual driving, and the operation-interface in the virtual driving is
dev_ioctl(struct?inode*inode,struct?file*file,unsigned?int?cmd,unsigned?long?arg)
The corresponding command word of cmd wherein, the corresponding parameter of arg.Virtual driving need be by the type of _ IOC_DIR (cmd) resolve command word, according to type with the composition transparent of command word and parameter pass to the service broker.
It is the same with said process that buffer size and other I/O control is set.
Main operation to sound card equipment is the read-write sound card.Application to the read-write of sound card corresponding to audio sound-recording and playback function.Interface with the voice applications compose buffer is the example introduction below.The interface of voice applications compose buffer is:
write(int?audio_fd,const?void*buffer,size_t?count)
Wherein audio_fd is the sound card equipment document number, and buffer is the buffer pointer of stores audio data, and count is the unit representation buffer size with the byte.This command mapping is to virtual driving, and the operation-interface in the virtual driving is
dev_write(struct?file*file,const?char*buffer,size_t?count,loff_t*ppos)
Wherein buffer is the pointer of the buffering area of reception user's space voice data, and count is a buffer size.Voice applications is reflected to virtual driving to the logic of writing of sound card, passes to the service broker afterwards pellucidly.
To write the logical mappings process similar for the logical AND of reading of voice applications, but data flow direction is opposite.
4) sound card closes
The device shutdown of voice applications passes to the service broker by virtual driving.
5) cancellation of virtual unit driving
Virtual driving is not in case after loading, generally can nullify from kernel.In order to satisfy the consistency that drives with standard device, virtual driving provides equipment to nullify interface, realizes by devfs_unregister_chrdev () and devfs_unregister ().
Above-mentioned introduction be core of the present invention---the embodiment that virtual unit drives.Service broker, terminal agency drive the communication port that has constituted device redirection jointly with virtual unit, and the key of enforcement is the definition of communication protocol.With voice applications the most frequent voice data taking place and be written as example, introduces the communication protocol between service and terminal agency below.
After the service broker receives the write operation order of virtual driving,, organize packet, send to the terminal agency according to the device redirection agreement of definition between the agency.If it is 4096 bytes that for example each write operation is write the voice data size, it is as follows then to make up packet:
Length |
Operation code |
Parameter type |
Parameter length |
Parameter value |
4100 |
3 |
B |
4096 |
Voice data |
Wherein length field is 4100 (1+1+2+4096), and it is 4100 bytes that expression sends data length overalls (not comprising length field); Command code is 3 to show that this is operating as write operation; Parameter type is " B ", show that follow-up data is a byte stream; Parameter length is 4096, shows that the parameter value field length is 4096 bytes; What parameter value was partly deposited is to be come by voice applications, and need write the voice data in the sound card.
Because the sound card write operation only need feed back success or not, therefore, return messages are simple, only describe whether successfully getting final product.If 4096 byte datas are for example once read in the IN type order that sound card is read or I/O operates etc., then return messages are as follows:
The success mark |
Length |
Parameter type |
Parameter length |
Parameter value |
1 |
4099 |
B |
4096 |
Voice data |
Wherein successful tag field is 1, and expression is returned effectively; Length field is 4099, and expression follow-up data length overall is 4099 bytes; The parameter type field is " B ", and the data that show the back are byte stream; Parameter length field is 4096, shows that parameter value length is 4096 bytes; Parameter value partly is a voice data.
Device redirection method of the present invention realizes simple, highly versatile.What realize on server is the virtual driving of light weight.Drive with standard and to compare, registration/cancellations of both device files is consistent with operation-interface, but the operation of equipment of reality do not carry out, but the operation logic of application is transmitted through the network to terminal, and feedback is back to application on the server.In this communication process, virtual driving often and be indifferent to the details of operation is just returned the device access logic by network delivery to terminal equipment and former road.Adopt above-mentioned communication description process can shield the difference of access from different devices details, have very strong versatility; Simultaneously by special interface is provided, the operation of equipment of some special requirement is provided support, have stronger extensibility; The communication logic of aforesaid way is clear, and the subclass of intelligent network application protocol, i.e. device redirection agreement are adopted in the network service between service broker and the terminal agency.
It should be noted that at last: above embodiment is the unrestricted technical scheme of the present invention in order to explanation only, although the present invention is had been described in detail with reference to the foregoing description, those of ordinary skill in the art is to be understood that: still can make amendment or be equal to replacement the present invention, and not breaking away from any modification or partial replacement of the spirit and scope of the present invention, it all should be encompassed in the middle of the claim scope of the present invention.