Link to home
Start Free TrialLog in
Avatar of softyan
softyan

asked on

Calling NT Service

Hi experts,
I got a few functions (eg. function A,B,C,D) and i would like to put these A,B,C,D functions as a one
and only one Service (or Daemon)in NT Server. This service run on the backgroud to serve many application . If application #1 call or using the service, application #2 and the rest cannot access the service....Now i don't know how to call the service from application and also don't know how to determine which application is calling the service.
Can someone give me a guide? Thanks in advance!!!:)

Regards,
Softyan Here
Avatar of softyan
softyan

ASKER

Edited text of question
I would recommend making a deamon process  that controls all the needed functions. Once a service is requested the deamon process can spawn a child process handling the requeted function. Once the function is finished the child process notifies the deamon telling that his service is available again.

So if another is asking for the service while it's still busy, the demaon process knowns is can either give an error message back, or just blocks the call until the service is free.

I once used this technique for writing a printer deamon servicing a number of printers, connected thru special hardware interfaces, which obviously could only be used by one program at a time.
Avatar of softyan

ASKER

hi elfie,
   Do u have any example that can show me how to do this?
It were drivers i wrote for my previous employer, and currently i have no useful example, unless i spend some time to it.

If you need some sample programs, the best you do is reject my answer, and ask for some sample program.

Avatar of softyan

ASKER

What's the different between a driver and the solution u that u proposed?
The software we wrote was part of a big project, in which we emulate a complete (out-dated) hardware (Nixdorf) On a UNIX environment.
One of the parts that we had to emulate was the printing facility that existed on the old hardware. For that we wrote a kind of spooling mechanism. But instead of what normal spooling is (request are queued but the programs who printed, can continue)
the emulation of the old hardware implied that that either the programs trying to print on a busy printer, either had to wait until sending their request, or just stop printing an retyr a bit later.

For this solution we made a deamon process (and a control file) so that we were able to see which 'printer'driver to use for which hardware device(printer). If the deamon process found that a printer driver was busy, it was returned a status back to the calling program. If the printer driver was not busy at the moment, the request was passed via the deamon process towards the printer driver. Then the program and printer driver set up their own socket connection, and teh program was able to print.
Once the printing was finished (a close operation of the printer), The printer driver send a request to the deamon telling that his service was free again.

The deamon process was listening on a global socket (defined in /etc/services). The start a printer driver, the deamon process does a 'fork', and then an exec of the correct printer driver.
The printer driver sets up a 'privat' listen queue, and send the number of 'privat' socket towards the demaon process.
If a program connects to the deamon, and the printer program is free, the deamon send the 'privat' socket number the program, which can directly connect the printer driver.

So we made a deamon process, that was controlling some (printer)drivers.


Hope this clarifies my previous comment
Avatar of softyan

ASKER

Thanks for helping, but since i'm using WindowsNT, i have to write a service to perform the task. I would like to know HOW the service is communicate with the application.
Hai..
  I think u know how to make an NT service . Then u can pass data to be communicated through any inter -processs commmunication techniques like pipe or u can use sockets etc.
 for eg in sockets it can wait for a connection and do the work so that no tohers can access it at that time and after processign it can accept  next app's request.

 I think u have got an idea .. please let me know if any clarifications needed..
Avatar of softyan

ASKER

Your comment is what i want, but do u have the example program that clarify the thing u said. i.e. (socket program, no others can access it at the same time). I am new to socket programming, i don't know the internal things of a socket program. I need your help to guide me through.

Thanks in advance! :)
I think what you want is a sample program which shows how to write a NT service ! I will send you by mail. Then you can give me the points what do you think ..send me a mail if you want that sample code ! at  rajkumar.r@usa.net
Avatar of softyan

ASKER

I have the sample code of NT Service, but what i want is the previously comment that I said. Thanks!
Why don't you try using RPC? It lets you call the function in one process and have it executed in another. It is fairly simple to use as long as you do not pass complex parameters to your functions.
Avatar of softyan

ASKER

Sorry, because of some other reasons, i cannot use RPC.

Set up your program as a service. This will require you to create the program and then register it as a service with the SCM (Service Control Manager). This basically involves creating a service routine and a handler function to handle the other messages from the SCM. Your service routine will call the programs real code (what you want it to do).

How do you call the service? Your service, once running, will need to listen to requests for functions A, B, C, and D. This can be done using pipes or sockets. The service will block waiting to accept incoming requests, receive data via the chosen IPC mechanism, process the request and then block again. Any external programs will use this IPC mechanism to use the service.

How do you determine who is calling the service? In the message passed to the service which requests function A, B, C, or D simply have the client state who it is. This is just a matter of the definition for your application layer protocol.

 
ASKER CERTIFIED SOLUTION
Avatar of nari
nari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softyan

ASKER

Actually, i already had the solution, but still thank those who give me the suggestion.