A kind of database subsystem method for designing based on DSS frameworks
Technical field
The present invention relates to a kind of database subsystem method for designing based on DSS frameworks.
Background technology
Darwin Streaming Server abbreviations DSS.DSS is the real time flow medium broadcasting of increasing income that Apple companies provide
Server program, whole program is write using pure C++, the programmings such as high-performance, simple, modularization is followed in design former
Then, must accomplish program efficiently, expandability is good, thus DSS server systems be in cross-platform support quite preferably,
It may operate in the windows kernel versions of Windows NT, Windows 2000 and the above, while operation that also can be good
On the various versions of * NIX, including Mac OS X, Linux, FreeBSD, Solaris, while the measured Streaming Medias of DSS
Agreement RTSP, RTP/RTCP are developed, thus on extremely strong popularity and versatility.
On this basis, DSS Frame Designs are complex into one, hierarchical structure more clearly streaming media server
System, mainly by basic function component(Network, string processing, internal memory opens up release, and module tool, internal error message is determined
Justice, global catalog etc.), each subsystem(RTSP, RTP, RTCP etc.), various functions plug-in unit(Authentication, identity
Authorize, data flow pretreatment, Data Stream Processing, the treatment of HTTP tunnels, server message is replied etc.)Combine, Hen Duokai
Hair personnel can mainly carry out the exploitation of various functions plug-in unit, dynamic load be carried out when startup of server, when main flow shape
The treatment of state machine to that will call corresponding plug-in unit when corresponding state, now is given plug-in unit and carries out corresponding work(by server by control
Can running.Therefore, on this basis from the angle using structure, server is divided into two bulks, server internal with
And outside server, server internal is made up of various basic function components and subsystem, by feature card outside server
Composition, the api interface being designed to by function pointer between the two parts carries out the interaction of data and the reality of basic function
It is existing.
But developer often needs to design plug-in unit incessantly during developing, while being also required to server
Inside carries out necessary function increase or modification, existing DSS frameworks for the data source outside audio and video data streams from
Loaded in configuration file, including startup of server a large amount of configuration parameters, the data needed in subsystem running, mould
Data required for block plug-in unit, such as, for authentication, for IP sections limitation of access etc., this is largely to item
Purpose is actually used to cause great inconvenience, therefore the function of addition database is during actual items are used in DSS frameworks
It is very necessary, and the database function design in existing DSS frameworks is relatively simple, not according to the timesharing of DSS frameworks
Feature, and database manipulation data promptness feature namely in the DSS timesharing frameworks the need for another database tasks produce
Raw preemption function, and original task is interrupted on the premise of the various states of original task are protected, in success from database
Obtain and recover original task again after data, cause using various unexpected serious problems above occur.In order to avoid
These problems, server characteristics and ODBC that summary of the present invention is mentioned(Open Database connect open number
According to interconnection)The database of mode is used, and detailed design is based on DSS timesharing framework ODBC subsystem functions.
The content of the invention
It is an object of the present invention to provide a kind of database subsystem method for designing based on DSS frameworks, solve
Database subsystem task is seized under existing DSS frameworks, function is simple and its derivative all kinds of problems.
To achieve these goals, technical scheme is as follows:
A kind of database subsystem method for designing based on DSS frameworks, comprises the following steps:
Step 1, in DSS modular constructions design database mission thread Similar integral from DSS system threads class, design database appoint
Business Similar integral is from DSS task class;The database tasks thread class is as database thread component for an independence and uniquely
Thread be responsible for propelling data storehouse task, and this thread is responsible for safeguarding a task heap, and this task heap is by nearest timeslice
Real work thread is sent in task ejection;The database tasks class is used to call static state initial when DSS startup of server
Change the thread in the mission thread class of function log-on data storehouse, be additionally operable to call database tasks class thread interface to perform database times
The operation of Priority Queues and each attribute and handling function for maintenance task in the insertion database tasks thread class of business,
The database tasks thread class and database task class friendly metaclass each other;
Step 2, design database subsystem class and subsystem execution interface class in DSS subsystem structures;The database subsystem
System class subsystem class is to be inherited from database interface class as a container first, is responsible for various database tasks coherence checks
And most important operation function, the operation function is for performing actual database manipulation and being stored in implementing result
It is real important execution function in database subsystem data dictionary in DSS data systems;The database interface is responsible for holding
The work of row data library initialization and the initialization of global catalog;
Increase the call back function of database manipulation in step 3, the call back function structure in the Private.h files of DSS frameworks
Definition;
Increase database manipulation function declaration in Callbacks.h files, while the increase sound in Callbacks.cpp files
Bright function;
The statement of reference data storehouse handling function in QTSS.h;
The function pointer assignment of database handling function in initialization callback function in qtsserver.cpp;It is complete
Designed into by the api interface of DSS lower portions to DSS framework external plug-ins.
Preferably, in the step 1, design database mission thread in the general utility tool class libraries in DSS modular constructions
Similar integral is inherited from the task class of DSS frameworks, database tasks thread class from DSS system threads class, design database task class
It is that the database tasks of unique operation in DSS frameworks promote thread as database thread component, is also to constitute database subset
The infrastructure component of system.
Preferably, the database tasks thread class includes a member variable for heap data structure, i.e. Priority Queues, this
Individual Priority Queues is formed by complete binary tree construction, and the father node of the complete binary tree is consistently greater than or less than left and right
Node, this Priority Queues is used to push away the nearest database tasks of timeslice toward root vertex, while also including becoming for heap
Amount seize the heap mutex of protection and drives the heap semaphore of heap variable work.
Preferably, the database tasks thread class includes an entrance function, and the function is used to judge whether to appoint
, there is task element in business element, if there is task element, entrance function is again when whether task heap length is more than 0
Judge whether the timeslice in current task element has arrived at time-out, ought if the timeslice of current task has timed, out
Preceding task is sent to carries out actual operating data storehouse task in the mission thread in DSS frameworks;
The database tasks thread class also includes an execution database statement function, and the execution database statement function is used for
By database tasks pointer propulsion reactor variable, while increasing length, the entrance function of driving task thread class is operated.
Preferably, the database tasks class includes a static initialization function and encapsulates database tasks thread class
In the real execution database statement function for performing function, static initialization function system initialization in system starting process
It is called during function, database tasks push thread and bring into operation when calling the static initialization function;
The execution database statement function is basic as the api interface of database, and the outside that will be supplied to DSS frameworks in API is inserted
Called when part is used.
Preferably, the database tasks class includes heap member's class, and heap member class becomes as the member of database tasks class
Amount, also serves as the member variable of this friendly metaclass of database tasks thread class, and heap member variable has the change for preserving task pointer
The time-out time of amount and current task timeslice;
The database tasks class also includes database tasks event enumeration structure, and number is worked as defined in task events enumeration structure
The event definition that needs are performed when DSS worker threads run is admitted to according to storehouse task is actual.
Preferably, database interface includes a static initialization function, and the static initialization function is in database subset
Called in advance before the formal startup of system, be responsible for carrying out opening up for global catalog to the related data of database subsystem, this
A little data dictionaries will be interacted in DSS lower portions and external plug-in and used.
Preferably, in the step 2, the design database subsystem in the Server.tproj structures of DSS subsystem structures
System class, varying string formatted class of this Similar integral from database interface and DSS frameworks.Class database will be used as true
Run in the worker thread of positive task carrier feeding DSS frameworks;
Also include step 4 after the step 3:Design database in the Server.tproj structures of DSS subsystem structures
The interface class of system, from dictionary class and database tasks class, wherein dictionary class is the data in DSS frameworks to the interface Similar integral
Dictionary class, this interface class is used to provide the various operate interfaces in the database manipulation for performing database mode, is additionally operable to protect
The value of each property parameters in deposit data storehouse, and for the returning result collection after the execution of in store database tasks.
Preferably, database includes a static initialization function, a real tasks carrying function and operation function,
The static initialization function carries out the auxiliary information initialization of task;The real tasks carrying function is in DSS frame work threads
In will be extracted execution;The operation function performs the database manipulation under database mode, and database manipulation is:Obtain first
SQL statement is taken, is then fed into database statement execution function, then obtained implementing result collection and count and end product storage
The data dictionary variable entered in database interface;
For the string format class that the result set of database operation function uses variable-length in DSS frameworks, this class exists
The space for becheduleding for size will be opened up when constructed fuction for depositing result set, if result set is more than becheduled for size
Space can automatically open up 2 times of spaces of life size.
Preferably, for database manipulation function:Perform during database statement inside is realized and pointed to using database object
The parameter of production database sentence is defaulted as 0, namely another database tasks need to be pushed into real work immediately from heap
Thread, while in returning to calling module, the API of database is once called and will be used one numerical value in units of millisecond of return
Carry out interrupting current task module.
After using such scheme, the beneficial effects of the invention are as follows:Timesharing feature according to DSS frameworks of the invention, and number
According to the promptness feature of storehouse peration data, the database subsystem method for designing of design solves database under existing DSS frameworks
Subsystem task is seized, function is simple and its derivative all kinds of problems, and the database subsystem of design can be in DSS lower portion sides
Just use database manipulation, and be opened to perfect database API operate interfaces and be supplied to DSS framework external plug-ins, make
The exploitation that DSS frameworks must be based on is more convenient, more meets the utilization of actual items.
Below in conjunction with the drawings and specific embodiments, the present invention will be further described.
Brief description of the drawings
Fig. 1:Modular construction schematic diagram of the database of the present invention in DSS frameworks;
Fig. 2;Structural representation of the database subsystem of the present invention in DSS frameworks;
Fig. 3-1;Database subsystem of the present invention driving condition schematic diagram in DSS frameworks;
Fig. 3-2 is to push into task class mission thread view the task of timeslice time-out(Wait 13 milliseconds of time values
Task has arrived at, and pushes out execution);
Fig. 3-3 is that will shift tree root view onto according to 14 milliseconds of time value tasks of wait of Priority Queues mode;
Fig. 3-4:Supplement schematic diagram is carried out to empty node;
Fig. 3-5:A complete quene state schematic diagram is formed again;
Fig. 4:Data subsystem of the present invention operation schematic diagram in DSS external plug-ins.
Specific embodiment
As shown in figure 1, a kind of database subsystem method for designing based on DSS frameworks that the present invention is disclosed, including it is following
Step:
The first step:In DSS modular constructions(General utility tool class libraries CommonUtlitiesLib)Middle design database mission thread
Class(ODBCTaskThread)It is inherited from DSS system thread classes(OSThread), design database task class(ODBCTask)After
Hold from DSS task class(Task), database tasks thread is responsible for propelling data storehouse task with an independent unique thread, this
Nearest timeslice task ejection in heap is sent to actual work by one task heap (Priority Queues) of bar thread major maintenance, this thread
Make thread:
Above-mentioned database tasks thread class and database task class friendly metaclass each other, database tasks thread class is used as database line
Journey component, is that the database tasks of unique operation in DSS frameworks promote thread, is also the base set for constituting database subsystem
Part;
Second step:The design database subsystem class in DSS subsystem structures (Server.tproj)(QTSSODBC)And son
System performs interface class(QTSSODBCInterface);Database subsystem class is to be inherited from data as a container first
Bank interface class, is responsible for various database tasks coherence checks and most important operation function(Run), this function mainly performs
Actual database manipulation and the database subsystem data dictionary that result is stored in DSS data systems, are real
Important execution function:
3rd step:For database interface class, it is inherited from database tasks class, and database tasks class is then inherited in DSS again
Task class, meanwhile, task class and system thread class friendly metaclass each other, when server initiation, database tasks class will
Static initialization function can be called to start log-on data storehouse thread, simultaneously as the entrance function of system thread class is Virtual Function,
Therefore database thread will run the unique thread of oneself, that is, database tasks push thread(Database tasks are pushed
Enter in heap variable Priority Queues):
4th step:Task class thread is constantly in wait state, and it can wait two kinds of arrivals of task status, and one kind is in office
The task more than 0 value is returned in business implementation procedure, such task will be stored in heap types of variables(Priority Queues)'s
In task queue, when timeslice is reached, preferentially ejecting in this queue for task is run;Second is common
The delivery of task, such task is delivered in normal task queue, when not existing task in Priority Queues
Waiting will search whether this common task queue has the task of timeslice time-out, and then bring into operation corresponding operation if any
Function:
5th step, as shown in Figure 2:When have one need by database manipulation interrupt task performed in task class thread when
Wait, she can return to a value in units of millisecond and be interrupted oneself, and task class mission thread will be by it after interruption
It is sent into the heap variable in task class thread(In Priority Queues), return value is worked as next time(Timeslice time-out)When arrival, appoint
Preferential performing in Priority Queues for task only can just be performed common appointing by business class after the tasks carrying in Priority Queues is complete
Task in business queue.Therefore after current task is preempted, preferential execution will be started and seizes task i.e. database data
The real executor operation function of storehouse task.Finally after the completion of cdr database tasks carrying, data pass through data word
Allusion quotation is sent into data field, resumes waiting for the tasks carrying being originally preempted, and now original task will obtain database data:
Database tasks thread class also includes an execution database statement function, and the execution database statement function is used for number
According to storehouse task pointer propulsion reactor variable, while increasing length, the entrance function of driving task thread class is operated
6th step, such as Fig. 3 series(Fig. 3-1,3-2,3-3,3-4)It is shown:How entrance function in task class thread is by the time
The task that piece has arrived at is pushed to the process of task class mission thread execution, is how to use Priority Queues shown in Fig. 3 series
Data structure come realize priority tasks push, Priority Queues is the class abstract data type in computer science, preferentially
The element that each element in queue has respective priority, highest priority is most served before;Priority identical unit
Order of the element according to it in Priority Queues is serviced, and Priority Queues is often realized with heap.In the present invention, Priority Queues
Priority tasks interrupt after again run required for wait timeslice represent, Fig. 3 series in if all nodes when
Between be worth(The priority of element in Priority Queues)Then to represent that database tasks will be performed immediately if 0, if other numbers
Value, then it represents that being interrupted for task needs to wait that timeslice how long is performed again.
7th step, as shown in Figure 4:Increase database number in call back function structure in DSS framework Private.h files
The call back function operated according to storehouse is defined, and the statement of cdr database handling function is then increased in Callbacks.h, while
Statement function is realized in Callbacks.cpp, the statement of reference data storehouse handling function, finally exists in QTSS.h
The function pointer assignment of database handling function in initialization callback function in qtsserver.cpp, completes by DSS
Lower portion is designed to the api interface of DSS framework external plug-ins.When its exterior plug-in unit needs to use database function, then adjust
With the api interface defined in system, while carrying out seizing safeguard protection to data dictionary.
The above-mentioned Private.h files of the present invention, Callbacks.h files, Callbacks.cpp files are DSS frameworks
In have been defined file, respectively possess its peculiar function.
Preferably, database tasks thread class includes a heap(Heap variable, heap)The member variable of data structure, i.e., it is excellent
First queue, this Priority Queues be by a complete binary tree construction form, the father node of the complete binary tree be consistently greater than or
Less than left and right child node, this Priority Queues is used to push away the nearest database tasks of timeslice toward root vertex, while also wrapping
Include the heap mutex for for heap variable seize protection(heapMutex)And drive the heap semaphore of heap variable work
(heapCond).
Preferably, the database tasks thread class includes an entrance function(Entry()), the function is for judgement
It is no to there is task element, there is task element when whether task heap length is more than 0, if there is task element, enter
Mouth function judges whether the timeslice in current task element has arrived at time-out again, if the timeslice of current task has surpassed
Be sent to for current task actual operating data storehouse task carried out in the mission thread in DSS frameworks by Shi Ze;Task class thread one
In being directly waited for, she can wait two kinds of arrivals of task status, and one kind is returned more than 0 value in task implementation procedure
Task, such task will be stored in heap types of variables(Priority Queues)Task queue in, when timeslice reach
When, preferentially ejecting in this queue for task is run.It is for second the delivery of common task, such
Business is delivered in normal task queue, and this common task queue will be searched when not existing task in Priority Queues
Whether the task of timeslice time-out is had, and then bring into operation corresponding operation function if any.
Preferably, the database tasks class includes a static initialization function(static void Initialize
())With the execution database statement function for encapsulating real execution function in database tasks thread class, the static initialization letter
Number is called in system starting process during system initialization function, and database tasks are pushed when calling the static initialization function
Thread brings into operation;
The execution database statement function is basic as the api interface of database, and the outside that will be supplied to DSS frameworks in API is inserted
Called when part is used.
Preferably, the database tasks class includes heap member's class, and heap member class is used as database tasks class(Pointer)'s
Member variable, also serves as the member variable of this friendly metaclass of database tasks thread class, and there is heap member variable preservation task to refer to
The variable of pin and the time-out time of current task timeslice;
The database tasks class also includes database tasks event enumeration structure, and number is worked as defined in task events enumeration structure
The event definition that needs are performed when DSS worker threads run is admitted to according to storehouse task is actual.
Preferably, database interface includes a static initialization function, and the static initialization function is in database subset
Called in advance before the formal startup of system, be responsible for carrying out opening up for global catalog to the related data of database subsystem, this
A little data dictionaries will be interacted in DSS lower portions and external plug-in and used.
Preferably, database includes a static initialization function, a real tasks carrying function and operation function,
The static initialization function carries out the auxiliary information initialization of task;The real tasks carrying function is in DSS frame work threads
In will be extracted execution;The operation function performs the database manipulation under database mode, and database manipulation is:Obtain first
SQL statement is taken, is then fed into database statement execution function, then obtained implementing result collection and count and end product storage
The data dictionary variable entered in database interface;
For the string format class that the result set of database operation function uses variable-length in DSS frameworks, this class exists
The space for becheduleding for size will be opened up when constructed fuction for depositing result set, if result set is more than becheduled for size
Space can automatically open up 2 times of spaces of life size.
Preferably, for database manipulation function:Perform during database statement inside is realized and pointed to using database object
The parameter of production database sentence is defaulted as 0, namely another database tasks need to be pushed into real work immediately from heap
Thread, while in returning to calling module, the API of database is once called and will be used one numerical value in units of millisecond of return
Carry out interrupting current task module, because database tasks start to seize, this value for being returned in units of millisecond is exactly
Business of formerly helding the post of needs to wait the time for re-executing, this time to need basis to be currently needed for sentencing the time of database manipulation
Have no progeny setting, prevent nested task.
Specific embodiment of the invention is these are only, not to the restriction of protection scope of the present invention.All setting according to this case
The equivalent variations that meter thinking is done, each fall within the protection domain of this case.