OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
wskservm.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Winsock for OWL subsystem.
7/// Based on work by Paul Pedriana, 70541.3223@compuserve.com
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_WSKSERVM_H)
11#define OWL_WSKSERVM_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18#include <owl/defs.h>
19#include <owl/window.h>
20
21#pragma pack(push, 8)
22#include <winsock.h>
23#pragma pack(pop)
24
25
26namespace owl {
27
28#define WINSOCK_NOERROR (int)0
29#define WINSOCK_ERROR (int)SOCKET_ERROR
30
31//
32// Is supposedly in RFC 883.
33//
34#define N_MAX_SERVICE_NAME 128
35#define MSG_SERVICE_NOTIFY ((UINT)(WM_USER+302))
36
37class _OWLCLASS TServiceManager;
38
39#include <owl/preclass.h>
40
41//
42/// \class TServiceWindow
43// ~~~~~ ~~~~~~~~~~~~~~
44/// TServiceWindow is a private class created by the TServiceManager to catch
45/// notifications.
46//
48 public:
49 TServiceWindow(TServiceManager* newServiceManagerParent);
50
51 protected: // CQ add this?
52 /// Object to pass notifications
53 //
55
57
59};
60
61//
62/// \class TServiceEntry
63// ~~~~~ ~~~~~~~~~~~~~
64/// Encapsulates information about a service.
65//
66class _OWLCLASS TServiceEntry : public servent {
67 public:
69};
70
71//
72/// \class TServiceManager
73// ~~~~~ ~~~~~~~~~~~~~~~
74/// The TServiceManager class (and its friend class TServiceWindow) encapsulate the
75/// Winsock database functions getservbyname(), getservbyport(),
76/// WSAAsyncGetServByName(), and WSAAsyncGetServByPort(). These blocking (get...)
77/// and non-blocking (WSA...) functions return information about the service name,
78/// port, and protocol when given only a service name or a port.
79//
81 public:
83 virtual ~TServiceManager();
84
85 int GetLastError();
87 int GetService(TServiceEntry*& sEntry, uint16 nPort, const char* szProtocol = 0);
88 int GetService(TServiceEntry*& sEntry, const char* szName,
89 const char* szProtocol = 0);
90 int GetServicePort(char* szName, uint16& nPort, const char* szProtocol = 0);
91 int GetServiceName(uint16 nPort, char* szName, const char* szProtocol = 0);
92 int GetServiceAsync(HANDLE& hService, uint16 nPort, const char* szProtocol = 0);
93 int GetServiceAsync(HANDLE& hService, char* szName, const char* szProtocol = 0);
94 int GetServiceAsync(TWindow& wndNotify, HANDLE& hService, uint16 nPort,
95 const char* szProtocol = 0, uint nMessage = MSG_SERVICE_NOTIFY,
96 char* chBuffer = 0);
97 int GetServiceAsync(TWindow& wndNotify, HANDLE& hService, char* szName,
98 const char* szProtocol = 0, uint nMessage = MSG_SERVICE_NOTIFY,
99 char* chBuffer = 0);
100 int CancelServiceRequest(HANDLE hService = 0);
102
104 /// Set to point to chServiceBuffer.
105 //
106 TServiceEntry* ServiceEntry;
107
108 protected:
109 int LastError; ///< Last error code
110 int OutstandingServiceRequests; ///< Count of total requests done by myself that haven't completed yet.
111 bool LastServiceRequestCompleted; ///< Is the last request done?
112 char ServiceBuffer[MAXGETHOSTSTRUCT]; ///< Used for calls to WSAAsync...()
113 HANDLE LastServiceRequest; ///< Handle of last service request
114 TServiceWindow Window; ///< Private window for catching notification
115
116 void ServiceCompleted(int nError);
117
118 friend class TServiceWindow;
119};
120
121#include <owl/posclass.h>
122
123
124//----------------------------------------------------------------------------
125// Inline implementations
126//
127
128//
129/// This function returns the last error code.
130//
131inline int
136
137//
138/// This function returns the last service completion.
139/// \todo why int return type?
140//
141inline int
146
147//
148/// This function returns true if the last service requested has been completed.
149//
150inline bool
155
156} // OWL namespace
157
158
159#endif // OWL_WSKSERVM_H
Encapsulates information about a service.
Definition wskservm.h:66
TServiceEntry()
Initializes all data members of servent to 0.
Definition wskservm.cpp:53
The TServiceManager class (and its friend class TServiceWindow) encapsulate the Winsock database func...
Definition wskservm.h:80
HANDLE LastServiceRequest
Handle of last service request.
Definition wskservm.h:113
bool LastServiceRequestCompleted
Is the last request done?
Definition wskservm.h:111
friend class TServiceWindow
Definition wskservm.h:118
int GetLastServiceCompletion()
This function returns the last service completion.
Definition wskservm.h:142
int GetServiceName(uint16 nPort, char *szName, const char *szProtocol=0)
This function is blocking.
Definition wskservm.cpp:152
int GetServiceAsync(HANDLE &hService, uint16 nPort, const char *szProtocol=0)
This call is non-blocking.
Definition wskservm.cpp:199
int GetServicePort(char *szName, uint16 &nPort, const char *szProtocol=0)
This function is blocking.
Definition wskservm.cpp:137
TServiceWindow Window
Private window for catching notification.
Definition wskservm.h:114
void ServiceCompleted(int nError)
This function is called whenever an internal window callback is used for an asynchronous call.
Definition wskservm.cpp:305
int GetService(TServiceEntry *&sEntry, uint16 nPort, const char *szProtocol=0)
Implements the blocking getservbyport().
Definition wskservm.cpp:102
TServiceManager()
This function creates the hidden window and initializes data members.
Definition wskservm.cpp:66
int GetLastError()
This function returns the last error code.
Definition wskservm.h:132
bool GetServiceRequestCompleted()
This function returns true if the last service requested has been completed.
Definition wskservm.h:151
int CancelServiceRequest(HANDLE hService=0)
This function cancels a pending service that equals the hService.
Definition wskservm.cpp:168
char ServiceBuffer[MAXGETHOSTSTRUCT]
Used for calls to WSAAsync...().
Definition wskservm.h:112
int OutstandingServiceRequests
Count of total requests done by myself that haven't completed yet.
Definition wskservm.h:110
int LastError
Last error code.
Definition wskservm.h:109
TServiceManager * ServiceManagerParent
Object to pass notifications.
Definition wskservm.h:54
TResult DoNotification(TParam1, TParam2)
This function merely calls the parent notification function.
Definition wskservm.cpp:42
DECLARE_RESPONSE_TABLE(TServiceWindow)
TServiceWindow(TServiceManager *newServiceManagerParent)
A TServiceWindow requires a TServiceManager parent.
Definition wskservm.cpp:27
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
Definition window.cpp:341
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
LRESULT TResult
Result type.
Definition dispatch.h:52
unsigned short uint16
Definition number.h:33
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define public_data
Definition defs.h:207
#define _OWLCLASS
Definition defs.h:338
Base window class TWindow definition, including HWND encapsulation.
Main header of the Winsock OWL subsystem.
#define MSG_SERVICE_NOTIFY
Definition wskservm.h:35