A kind of database subsystem design method based on DSS frame
Technical field
The present invention relates to a kind of database subsystem design methods based on DSS frame.
Background technique
Darwin Streaming Server abbreviation DSS.DSS is that the open source real time flow medium that Apple company provides plays
Server program, entire program are write using pure C++, and it is former to follow the programmings such as high-performance, simple, modularization in design
Then, must accomplish that program is efficient, expandability is good, therefore DSS server system be in cross-platform support it is quite ideal,
It may operate in the windows kernel version of Windows NT, 2000 Windows or more, while good can also run
In the various versions of * NIX, including the measured Streaming Media of Mac OS X, Linux, FreeBSD, Solaris, while DSS
Agreement RTSP, RTP/RTCP is developed, therefore has extremely strong popularity and versatility with upper.
On this basis, DSS Frame Design is more complicated at one, the relatively clear streaming media server of hierarchical structure
System, mainly by basic function component, (network, string processing, memory open up release, module tool, and internal error message is determined
Justice, global catalog etc.), each subsystem (RTSP, RTP, RTCP etc.), various feature card (authentication, identity
Authorization, data flow pretreatment, Data Stream Processing, the processing of the tunnel HTTP, server message reply etc.) it is composed, Hen Duokai
Hair personnel mainly will do it the exploitation of various feature cards, dynamically load be carried out when server starting, when main flow shape
Corresponding plug-in unit will be called when the processing of state machine is to corresponding state, server gives control to plug-in unit and carries out corresponding function at this time
It can running.Therefore, on this basis from the angle for using structure, server is divided into two bulks, server internal with
And outside server, server internal is made of various basic function components and subsystem, by feature card outside server
It forms, the interaction of data and the reality of basic function is carried out by the api interface that function pointer is designed between the two parts
It is existing.
However developer often needs to design plug-in unit during developing incessantly, while being also required to server
Inside carries out necessary function increase or modification, existing DSS frame for the data source except audio and video data streams from
It is loaded in configuration file, a large amount of configuration parameters including server starting, the data needed in subsystem operational process, mould
Data required for block plug-in unit, such as authentication, for IP sections of limitation etc. of access, this is largely to item
Purpose actual use causes great inconvenience, therefore it is during actual items are used that the function of database, which is added, in DSS frame
It is very necessary, and the database function design in existing DSS frame is relatively simple, there is no the timesharing according to DSS frame
The another database tasks of needs of the timeliness feature of feature and database manipulation data namely in DSS timesharing frame produce
Raw preemption function, and original task is interrupted under the premise of protecting original task various states, in success from database
It obtains data and restores original task again later, cause to will appear various unexpected serious problems in use.In order to avoid
These problems, the open number of in summary server characteristics and ODBC(Open Database connect that the present invention mentions
According to interconnection) database of mode uses, and detailed design is based on DSS timesharing frame ODBC subsystem function.
Summary of the invention
It is an object of the present invention to provide a kind of database subsystem design methods based on DSS frame, solve
Database subsystem task is seized under existing DSS frame, function is simple and its derivative all kinds of problems.
To achieve the goals above, technical scheme is as follows:
A kind of database subsystem design method based on DSS frame, comprising the following steps:
Step 1, in DSS modular construction design database mission thread Similar integral from DSS system thread class, design data
Library task class is inherited from DSS task class;The database tasks thread class be used for as database thread component with an independence and
Unique thread is responsible for propelling data library task, and this thread is responsible for safeguarding a task heap, when this task heap will be nearest
Between piece task pop-up be sent to real work thread;The database tasks class is used to call when the starting of DSS server static
Thread in the mission thread class of initialization function log-on data library is also used to that database tasks class thread interface is called to execute data
Library task insertion database mission thread class in Priority Queues operation and for each attribute of maintenance task and operation
Function, the database tasks thread class and database task class friendly metaclass each other;
Step 2, design database subsystem class and subsystem execute interface class in DSS subsystem structure;The data
Library subsystem class subsystem class is to be inherited from database interface class as a container first, and it is related to be responsible for various database tasks
It checks and most important operation function, the operation function is used to execute actual database manipulation and store implementing result
In the database subsystem data dictionary in DSS data system, for real important execution function;The database interface is responsible for
Execute the initialization of database initial work and global catalog;
Step 3, the readjustment for increasing database manipulation in the call back function structure in the Private.h file of DSS frame
Function definition;
Increase database manipulation function declaration in Callbacks.h file, while increasing in Callbacks.cpp file
Add statement function;
The statement of reference data library handling function in QTSS.h;
The function pointer of database handling function is assigned in initialization callback function in qtsserver.cpp
Value;It completes to be designed by the api interface of DSS lower portion to DSS frame external plug-in.
Preferably, in the step 1, the design database mission thread in the general utility tool class libraries in DSS modular construction
Similar integral is inherited from the task class of DSS frame, database tasks thread class from DSS system thread class, design database task class
It is that the database tasks uniquely run in DSS frame push thread, and constitute database subset as database thread component
The infrastructure component of system.
Preferably, the database tasks thread class includes the member variable of a heap data structure, i.e. Priority Queues, this
A Priority Queues is constructed by a complete binary tree, and the father node of the complete binary tree is consistently greater than or is less than left and right
Node, this Priority Queues are used to push away the nearest database tasks of timeslice toward root vertex, while also including that heap is become
Amount seize the heap mutex of protection and the heap semaphore of driving heap variable work.
Preferably, the database tasks thread class includes an entrance function, which appoints for judging whether there is
Business element, when whether task heap length is greater than 0, there are task elements, if having existed task element, entrance function is again
Judge whether the timeslice in current task element has arrived at time-out, will work as if the timeslice of current task has timed, out
Preceding task is sent to progress actual operating data library task in the mission thread in DSS frame;
The database tasks thread class further includes an execution database statement function, the execution database statement function
For by database tasks pointer propulsion reactor variable, while increasing length, the entrance function of driving task thread class works.
Preferably, the database tasks class includes a static initialization function and encapsulates database tasks thread class
In really execute the execution database statement function of function, static initialization function system initialization during the system startup process
It is called when function, database tasks push thread brings into operation when calling the static initialization function;
Api interface basis of the execution database statement function as database will be supplied to the outer of DSS frame in API
It is called when portion's plug-in unit use.
Preferably, the database tasks class includes heap member's class, and heap member class becomes as the member of database tasks class
Amount, also the member variable as this friend's metaclass of database tasks thread class, heap member variable have the change for saving task pointer
The time-out time of amount and current task timeslice;
The database tasks class further includes database tasks event enumeration structure, is defined in task events enumeration structure
The event definition needed to be implemented when the operation of DSS worker thread is admitted to when database tasks are practical.
Preferably, database interface includes a static initialization function, and the static initialization function is in database subset
It is called in advance before the formal starting of system, is responsible for carrying out opening up for global catalog to the related data of database subsystem, this
A little data dictionaries will interact use in DSS lower portion and external plug-in.
Preferably, in the step 2, the design database subsystem in the Server.tproj structure of DSS subsystem structure
It unites class, this Similar integral is from the varying string formatted class in database interface and DSS frame.Class database will be as true
Positive task carrier is sent into the worker thread of DSS frame and is run;
It further include step 4 after the step 3: the design data in the Server.tproj structure of DSS subsystem structure
The interface class of library subsystem, the interface Similar integral is from dictionary class and database tasks class, and wherein dictionary class is in DSS frame
Data dictionary class, this interface class are used to provide the various operation interfaces in the database manipulation for executing database mode, also use
In the value for saving each property parameters in database, and for returning the result collection after the execution of in store database tasks.
Preferably, database includes a static initialization function, a real task execution function and operation function,
The static initialization function carries out the auxiliary information initialization of task;The real task execution function is in DSS frame work thread
In will be extracted execution;The operation function executes the database manipulation under database mode, database manipulation are as follows: obtain first
SQL statement is taken, database statement is then fed into and executes in function, then obtains the counting of implementing result collection and final result storage
Into the data dictionary variable in database interface;
The string format class of variable-length in DSS frame is used for the result set of database operation function, this
Class will open up the space for becheduleding for size for storing result set when constructed fuction, becheduled for if result set is greater than
The space of size can open up the space of 2 times of life size automatically.
Preferably, for database manipulation function: executing and be directed toward in being realized inside database statement using database object
The parameter of production database sentence is defaulted as 0, namely another database tasks needs are pushed into real work immediately from heap
Thread, while returning in calling module, the API of database returns to the numerical value as unit of millisecond once calling and will use
It carries out interrupting current task module.
After adopting the above scheme, the beneficial effects of the present invention are: the present invention is according to the timesharing feature of DSS frame, and number
According to the timeliness feature of library operation data, the database subsystem design method of design, solves database under existing DSS frame
Subsystem task is seized, function is simple and its derivative all kinds of problems, and the database subsystem of design can be in the lower portion side DSS
Just use database manipulation, and be opened to perfect database API operation interface and be supplied to DSS frame external plug-in, make
It is more convenient to obtain the exploitation based on DSS frame, more meets the utilization of actual items.
Below in conjunction with the drawings and specific embodiments, the present invention will be further described.
Detailed description of the invention
Fig. 1: component structure diagram of the database of the present invention in DSS frame;
Fig. 2;Structural schematic diagram of the database subsystem of the present invention in DSS frame;
Fig. 3-1;Database subsystem of the present invention driving condition schematic diagram in DSS frame;
Fig. 3-2 is to push the task of timeslice time-out into task class mission thread status diagram (when waiting 13 milliseconds
Between value task have arrived at, push out execution);
Fig. 3-3 is that will shift tree root status diagram onto according to 14 milliseconds of time value tasks of waiting 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-in.
Specific embodiment
As shown in Figure 1, a kind of database subsystem design method based on DSS frame that the present invention discloses, including it is following
Step:
Step 1: the design database task in DSS modular construction (general utility tool class libraries CommonUtlitiesLib)
Thread class (ODBCTaskThread) is inherited from DSS system thread class (OSThread), design database task class
(ODBCTask) it is inherited from DSS task class (Task), database tasks thread is responsible for push with an independent unique thread
Database tasks, one task heap (Priority Queues) of this thread major maintenance, this thread is by timeslice task nearest in heap
Real work thread is sent in pop-up:
Above-mentioned database tasks thread class and database task class friendly metaclass each other, database tasks thread class is as data
Library thread component is that the database tasks uniquely run in DSS frame push thread, and constitute the basis of database subsystem
Component;
Step 2: in DSS subsystem structure (Server.tproj) design database subsystem class (QTSSODBC) with
And subsystem executes interface class (QTSSODBCInterface);Database subsystem class is inherited from as a container first
Database interface class, is responsible for various database tasks coherence checks and most important operation function (Run), this function are main
It executes actual database manipulation and result is stored in the database subsystem data dictionary in DSS data system, be true
Positive important execution function:
Step 3: for database interface class, it is inherited from database tasks class, database tasks class then inherit again in
DSS task class, meanwhile, task class and system thread class friendly metaclass each other, when server initiation, database tasks class
Static initialization function will be called to start log-on data library thread, simultaneously as the entrance function of system thread class is empty letter
Number, therefore database thread will run the unique thread of oneself, that is, database tasks push thread (pushes away database tasks
It is sent into heap variable Priority Queues):
Step 4: task class thread is constantly in wait state, it can wait the arrival of two kinds of task statuses, one is
Being greater than 0 value of the task is returned in task implementation procedure, such task will be stored in heap types of variables (preferential team
Column) task queue in, when timeslice reach when, preferentially popping up in this queue for task is run;Second
It is the delivery of common task, such task is delivered in normal task queue, when there is no appoint in Priority Queues
To be searched when business this common task queue whether the task of having time piece time-out, then bring into operation correspondence if any
Operation function:
5th step, as shown in Figure 2: when there is one to need to be executed in task class thread by the task that database manipulation interrupts
When, she can return to a value as unit of millisecond and interrupt oneself, and task class mission thread will after interruption
The heap variable (in Priority Queues) being fed into task class thread, next time when return value (timeslice time-out) reaches
It waits, task class only can just execute preferential executing in Priority Queues for task after the task execution in Priority Queues is complete
Task in common task queue.Therefore after current task is preempted, preferential execute will be started and seize task i.e. data
The real executor of library database tasks runs function.Finally after cdr database task execution is completed, data pass through
Data dictionary is sent into data field, resumes waiting for the task execution being originally preempted, original task will obtain database data at this time:
Database tasks thread class further includes an execution database statement function, which is used for
By database tasks pointer propulsion reactor variable, while increasing length, the entrance function of driving task thread class works
Shown in 6th step, such as Fig. 3 serial (Fig. 3-1,3-2,3-3,3-4): the entrance function in task class thread how will
The task that timeslice has arrived at is pushed to the process of task class mission thread execution, how is using preferential shown in Fig. 3 series
The data structure of queue come realize priority tasks push, Priority Queues is a kind of abstract data type in computer science,
Each element in Priority Queues has respective priority, and the element of highest priority is most served before;Priority is identical
Element serviced according to its sequence in Priority Queues, Priority Queues is often realized with heap.In the present invention, preferentially
The required timeslice waited of operation indicates again after the priority of queue tasks interrupt, if all nodes in Fig. 3 series
Time value (priority of element in Priority Queues) be 0 if then indicate that database tasks will be performed immediately, if it is it
His numerical value, then it represents that being interrupted for task needs that timeslice how long is waited to be performed again.
7th step, as shown in Figure 4: in the call back function structure in DSS frame Private.h file increase database number
According to the call back function definition of library operation, then increases cdr database handling function in Callbacks.h and state, while
Statement function is realized in Callbacks.cpp, the statement of reference data library handling function, finally exists in QTSS.h
The function pointer assignment of database handling function in initialization callback function in qtsserver.cpp is completed by DSS
The api interface of lower portion to DSS frame external plug-in designs.When exterior plug-in unit needs then to adjust using database function
With the api interface defined in system, while data dictionary is carried out to seize safeguard protection.
The above-mentioned Private.h file of the present invention, Callbacks.h file, Callbacks.cpp file are DSS frames
In have been defined file, have its peculiar function respectively.
Preferably, database tasks thread class includes the member variable of heap (heap variable, heap) data structure, i.e., excellent
First queue, this Priority Queues are constructed by a complete binary tree, 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 semaphore of the heap mutex (heapMutex) and driving heap variable work that seize for heap variable protection
(heapCond).
Preferably, the database tasks thread class includes an entrance function (Entry()), which is for judgement
No there are task elements, and when whether task heap length is greater than 0, there are task elements, if having existed 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
Current task is sent progress actual operating data library task in the mission thread in DSS frame by Shi Ze;Task class thread one
In being directly waited for, she can wait the arrival of two kinds of task statuses, and one is return to be greater than 0 value in task implementation procedure
Task, such task will be stored in the task queue of heap types of variables (Priority Queues), when timeslice reaches
When, preferentially popping up in this queue for task is run.It is for second the delivery of common task, such
Business is delivered in normal task queue, will search this common task queue when task is not present in Priority Queues
Whether the task of having time piece time-out, then bring into operation corresponding operation function if any.
Preferably, the database tasks class includes a static initialization function (static void Initialize
()) and encapsulate the execution database statement function that function is really executed in database tasks thread class, the static initialization letter
Count called when system initialization function during the system startup process, database tasks push when calling the static initialization function
Thread brings into operation;
Api interface basis of the execution database statement function as database will be supplied to the outer of DSS frame in API
It is called when portion's plug-in unit use.
Preferably, the database tasks class includes heap member's class, and heap member class is as database tasks class (pointer)
Member variable, also there is preservation task to refer to for the member variable as this friend's metaclass of database tasks thread class, heap member variable
The variable of needle and the time-out time of current task timeslice;
The database tasks class further includes database tasks event enumeration structure, is defined in task events enumeration structure
The event definition needed to be implemented when the operation of DSS worker thread is admitted to when database tasks are practical.
Preferably, database interface includes a static initialization function, and the static initialization function is in database subset
It is called in advance before the formal starting of system, is responsible for carrying out opening up for global catalog to the related data of database subsystem, this
A little data dictionaries will interact use in DSS lower portion and external plug-in.
Preferably, database includes a static initialization function, a real task execution function and operation function,
The static initialization function carries out the auxiliary information initialization of task;The real task execution function is in DSS frame work thread
In will be extracted execution;The operation function executes the database manipulation under database mode, database manipulation are as follows: obtain first
SQL statement is taken, database statement is then fed into and executes in function, then obtains the counting of implementing result collection and final result storage
Into the data dictionary variable in database interface;
The string format class of variable-length in DSS frame is used for the result set of database operation function, this
Class will open up the space for becheduleding for size for storing result set when constructed fuction, becheduled for if result set is greater than
The space of size can open up the space of 2 times of life size automatically.
Preferably, for database manipulation function: executing and be directed toward in being realized inside database statement using database object
The parameter of production database sentence is defaulted as 0, namely another database tasks needs are pushed into real work immediately from heap
Thread, while returning in calling module, the API of database returns to the numerical value as unit of millisecond once calling and will use
Interruption current task module is carried out because database tasks start to seize is exactly for this value returned as unit of millisecond
Business of formerly helding the post of needs to wait the time re-executed, this time needs basis currently to need to sentence the time of database manipulation
It has no progeny setting, prevents nested task.
The above is only specific embodiments of the present invention, 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 falls within the protection scope of this case.