Организация удаленного доступа к распределенным базам данных
Рефераты >> Программирование и компьютеры >> Организация удаленного доступа к распределенным базам данных

{

HINSTANCE hLib;

FARPROC hProc;

InterlockedIncrement(&TaskCount);

WaitForSingleObject(hConfigMutex, INFINITE);

MessageBeep(1);

if (hLib = LoadLibrary((char *)&((struct TASKENTRY*)ThreadParm)->DllName)) {

if (((struct TASKENTRY*)ThreadParm)->TermProc = GetProcAddress(hLib, (LPCSTR)TaskProcName))

{

((struct TASKENTRY*)ThreadParm)->Active = TRUE;

ReleaseMutex(hConfigMutex);

if (hProc = GetProcAddress(hLib, (LPCSTR)TaskProcName)) {

hProc();

try {

WaitForSingleObject(hConfigMutex, INFINITE);

((struct TASKENTRY*)ThreadParm)->Active = FALSE;

CloseHandle((HANDLE)((struct TASKENTRY*)ThreadParm)->TaskThread);

}

finally {

ReleaseMutex(hConfigMutex);

}

} else LogEvent(EVENTLOG_ERROR_TYPE, "Error Getting Procedure Address");

} else LogEvent(EVENTLOG_ERROR_TYPE, "Error Getting TermProc Address");

} else {

ReleaseMutex(hConfigMutex);

LogEvent(EVENTLOG_ERROR_TYPE, "Error Loading Library");

}

InterlockedDecrement(&TaskCount);

return 0;

}

void AnalyseTaskTable()

{

DWORD CurrTime;

int i;

CurrTime = GetTimeInMins();

try {

WaitForSingleObject(hConfigMutex, INFINITE);

for (i = 0; i < EntryCount; i++) {

if ((TaskTable[i].ExecTime == CurrTime) &&

(!TaskTable[i].Active)) {

CreateThread(NULL, 0, TaskProc, &TaskTable[i], 0, &TaskTable[i].TaskThread);

}

}

}

finally {

ReleaseMutex(hConfigMutex);

}

}

DWORD GetTimeInMins()

{

SYSTEMTIME SysTime;

GetLocalTime(&SysTime);

return SysTime.wHour*60+SysTime.wMinute;

}

void TerminateTasks()

{

int i;

DWORD TaskIndex = 0;

HANDLE Handles[TASK_COUNT];

for (i = 0; i < EntryCount; i++) {

if (TaskTable[i].Active) {

TaskTable[i].TermProc();

Handles[TaskIndex++] = (HANDLE)TaskTable[i].TaskThread;

}

}

WaitForMultipleObjects(TaskIndex, Handles, TRUE, INFINITE);

}

Comm.h

/* this ALWAYS GENERATED file contains the definitions for the interfaces */

/* File created by MIDL compiler version 3.00.15 */

/* at Tue Jun 03 11:35:46 1997

*/

/* Compiler settings for comm.idl:

Os, W1, Zp8, env=Win32, ms_ext, c_ext, oldnames

error checks: none

*/

//@@MIDL_FILE_HEADING( )

#include "rpc.h"

#include "rpcndr.h"

#ifndef comm_h

#define comm_h

#ifdef cplusplus

extern "C"{

#endif

/* Forward Declarations */

void RPC_FAR * RPC_USER MIDL_user_allocate(size_t);

void RPC_USER MIDL_user_free( void RPC_FAR * );

#ifndef CommService_INTERFACE_DEFINED

#define CommService_INTERFACE_DEFINED

/****************************************

* Generated header for interface: CommService

* at Tue Jun 03 11:35:46 1997

* using MIDL 3.00.15

****************************************/

/* [implicit_handle][version][uuid] */

void RefreshIniProps( void);

extern handle_t CommServ_IfHandle;

extern RPC_IF_HANDLE CommService_ClientIfHandle;

extern RPC_IF_HANDLE CommService_ServerIfHandle;

#endif /* CommService_INTERFACE_DEFINED */

/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */

#ifdef cplusplus

}

#endif

#endif

DoService.h

/**************************************************************/

/* DoService Module - implementation of initialisation other

/* tasks */

/* */

/* Copuright (c) 1997 by Malkov O.V. */

/* JSC "Svyazinform" RM */

/**************************************************************/

#ifndef DOSERVICE

#define DESERVICE

void ServerProcess();

DWORD ServerInit();

void ServerDoPause();

void ServerDoStop();

void ServerDoContinue();

#endif

CommonConfig.h

/**************** Server Engine Header File *******************/

#ifndef COMMON_CONFIG

#define COMMON_CONFIG

#define TASK_COUNT 10

#include " /RegistryConfig.h"

extern DWORD ConfigWatchingThread;

extern HANDLE hConfigMutex;

extern HANDLE hTaskMutex;

extern unsigned char *pszProtocolSequence;

extern unsigned char *pszSecurity;

extern unsigned char *pszEndpoint;

extern unsigned int cMinCalls;

extern unsigned int cMaxCalls;

extern unsigned int fDontWait;

extern struct TASKENTRY TaskTable[TASK_COUNT];

extern int EntryCount;

extern DWORD TaskThreads[TASK_COUNT];

extern int TaskCount;

DWORD WINAPI CommonConfigWatcher(LPVOID ThreadParm);

void UpdateVariables();

#endif

EventLog.h

#ifndef EVENT_LOG

#define EVENT_LOG

void LogEvent(WORD EventType, LPSTR EventMsg);

#endif

ClientHandler.h

#ifndef CLIENT_HANDLER

#define CLIENT_HANDLER

extern DWORD ClientHandlingThread;

DWORD WINAPI RPCClientHandling(LPVOID ThreadParm);

void RefreshIniProps();

#endif

ShedulerServ.h

#ifndef SHEDULING_SERVICE

#define SHEDULING_SERVICE

#define TaskProcName "TaskProc"

extern BOOL TerminateSheduling;

extern DWORD ShedulingThread;

DWORD WINAPI ShedulingProc(LPVOID ThreadParm);

void TerminateTasks();

#endif

RegistryConfig.h

#ifndef REGISTRY_CONFIG

#define REGISTRY_CONFIG

#define REGISTRY_TASKS_PATH "SOFTWARE\\Svyazinform\\CommService\\Tasks"

struct TASKENTRY

{

DWORD ExecTime;

char DllName[256];

FARPROC TermProc;

DWORD TaskThread;

BOOL Active;

};

#endif

Comm.idl

/* IDL File */

[ uuid (4a25d2e0-6703-11d0-8927-00a02413850e),

version(1.0)

]

interface CommService

{

void RefreshIniProps();

}

Comm.acf

/* acf file for TimeInclude Service (RPC) */

[ implicit_handle(handle_t CommServ_IfHandle)

]interface CommService

{

}

Приложение 4

Исходные тексты программы установки коммуникационного сервиса

#include <windows.h>

#include <stdio.h>

void RegEventSource();

VOID _CRTAPI1 main(void)

{

LPCTSTR lpszBinaryPathName =

TEXT("c:\\ibserver\\bin\\CommServ.exe");

SC_HANDLE schSCManager;

SC_HANDLE schService;

/* Open a handle to the SC Manager database. */

schSCManager = OpenSCManager(

NULL, /* local machine */

NULL, /* ServicesActive database */

SC_MANAGER_ALL_ACCESS); /* full access rights */

if (schSCManager == NULL) {

printf("\nError opening Service Manager.\n");

return;

}

schService = CreateService(

schSCManager, /* SCManager database */

TEXT("CommServ"), /* name of service */

TEXT("JSC \"SvjazInform\" Communication Service"), /* service name to display */

SERVICE_ALL_ACCESS, /* desired access */

SERVICE_WIN32_OWN_PROCESS, /* service type */


Страница: