public/steam/isteamclient.h
author Nicholas Hastings <nshastings@gmail.com>
Sun Nov 03 09:37:43 2013 -0500 (2013-11-03)
changeset 29 e827f56d0c8f
permissions -rw-r--r--
Recompile linux and mac tier1.
     1 //========= Copyright Valve Corporation, All rights reserved. ============//
     2 //
     3 // Purpose: Main interface for loading and accessing Steamworks API's from the 
     4 //			Steam client.
     5 //			For most uses, this code is wrapped inside of SteamAPI_Init()
     6 //=============================================================================
     7 
     8 #ifndef ISTEAMCLIENT_H
     9 #define ISTEAMCLIENT_H
    10 #ifdef _WIN32
    11 #pragma once
    12 #endif
    13 
    14 #include "steamtypes.h"
    15 #include "steamclientpublic.h"
    16 
    17 // Define compile time assert macros to let us validate the structure sizes.
    18 #define VALVE_COMPILE_TIME_ASSERT( pred ) typedef char compile_time_assert_type[(pred) ? 1 : -1];
    19 
    20 #if defined(__linux__) || defined(__APPLE__) 
    21 // The 32-bit version of gcc has the alignment requirement for uint64 and double set to
    22 // 4 meaning that even with #pragma pack(8) these types will only be four-byte aligned.
    23 // The 64-bit version of gcc has the alignment requirement for these types set to
    24 // 8 meaning that unless we use #pragma pack(4) our structures will get bigger.
    25 // The 64-bit structure packing has to match the 32-bit structure packing for each platform.
    26 #define VALVE_CALLBACK_PACK_SMALL
    27 #else
    28 #define VALVE_CALLBACK_PACK_LARGE
    29 #endif
    30 
    31 #if defined( VALVE_CALLBACK_PACK_SMALL )
    32 #pragma pack( push, 4 )
    33 #elif defined( VALVE_CALLBACK_PACK_LARGE )
    34 #pragma pack( push, 8 )
    35 #else
    36 #error ???
    37 #endif 
    38 
    39 typedef struct
    40 {
    41     uint32 m_u32;
    42     uint64 m_u64;
    43     uint16 m_u16;
    44     double m_d;
    45 } ValvePackingSentinel_t;
    46 
    47 #pragma pack( pop )
    48 
    49 
    50 #if defined(VALVE_CALLBACK_PACK_SMALL)
    51 VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 24 )
    52 #elif defined(VALVE_CALLBACK_PACK_LARGE)
    53 VALVE_COMPILE_TIME_ASSERT( sizeof(ValvePackingSentinel_t) == 32 )
    54 #else
    55 #error ???
    56 #endif
    57 
    58 
    59 // handle to a communication pipe to the Steam client
    60 typedef int32 HSteamPipe;
    61 // handle to single instance of a steam user
    62 typedef int32 HSteamUser;
    63 // function prototype
    64 #if defined( POSIX )
    65 #define __cdecl
    66 #endif
    67 extern "C" typedef void (__cdecl *SteamAPIWarningMessageHook_t)(int, const char *);
    68 
    69 #if defined( __SNC__ )
    70 	#pragma diag_suppress=1700	   // warning 1700: class "%s" has virtual functions but non-virtual destructor
    71 #endif
    72 
    73 // interface predec
    74 class ISteamUser;
    75 class ISteamGameServer;
    76 class ISteamFriends;
    77 class ISteamUtils;
    78 class ISteamMatchmaking;
    79 class ISteamContentServer;
    80 class ISteamMatchmakingServers;
    81 class ISteamUserStats;
    82 class ISteamApps;
    83 class ISteamNetworking;
    84 class ISteamRemoteStorage;
    85 class ISteamScreenshots;
    86 class ISteamGameServerStats;
    87 class ISteamPS3OverlayRender;
    88 class ISteamHTTP;
    89 class ISteamUnifiedMessages;
    90 
    91 //-----------------------------------------------------------------------------
    92 // Purpose: Interface to creating a new steam instance, or to
    93 //			connect to an existing steam instance, whether it's in a
    94 //			different process or is local.
    95 //
    96 //			For most scenarios this is all handled automatically via SteamAPI_Init().
    97 //			You'll only need to use these interfaces if you have a more complex versioning scheme,
    98 //			where you want to get different versions of the same interface in different dll's in your project.
    99 //-----------------------------------------------------------------------------
   100 class ISteamClient
   101 {
   102 public:
   103 	// Creates a communication pipe to the Steam client
   104 	virtual HSteamPipe CreateSteamPipe() = 0;
   105 
   106 	// Releases a previously created communications pipe
   107 	virtual bool BReleaseSteamPipe( HSteamPipe hSteamPipe ) = 0;
   108 
   109 	// connects to an existing global user, failing if none exists
   110 	// used by the game to coordinate with the steamUI
   111 	virtual HSteamUser ConnectToGlobalUser( HSteamPipe hSteamPipe ) = 0;
   112 
   113 	// used by game servers, create a steam user that won't be shared with anyone else
   114 	virtual HSteamUser CreateLocalUser( HSteamPipe *phSteamPipe, EAccountType eAccountType ) = 0;
   115 
   116 	// removes an allocated user
   117 	virtual void ReleaseUser( HSteamPipe hSteamPipe, HSteamUser hUser ) = 0;
   118 
   119 	// retrieves the ISteamUser interface associated with the handle
   120 	virtual ISteamUser *GetISteamUser( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   121 
   122 	// retrieves the ISteamGameServer interface associated with the handle
   123 	virtual ISteamGameServer *GetISteamGameServer( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   124 
   125 	// set the local IP and Port to bind to
   126 	// this must be set before CreateLocalUser()
   127 	virtual void SetLocalIPBinding( uint32 unIP, uint16 usPort ) = 0; 
   128 
   129 	// returns the ISteamFriends interface
   130 	virtual ISteamFriends *GetISteamFriends( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   131 
   132 	// returns the ISteamUtils interface
   133 	virtual ISteamUtils *GetISteamUtils( HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   134 
   135 	// returns the ISteamMatchmaking interface
   136 	virtual ISteamMatchmaking *GetISteamMatchmaking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   137 
   138 	// returns the ISteamMatchmakingServers interface
   139 	virtual ISteamMatchmakingServers *GetISteamMatchmakingServers( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   140 
   141 	// returns the a generic interface
   142 	virtual void *GetISteamGenericInterface( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   143 
   144 	// returns the ISteamUserStats interface
   145 	virtual ISteamUserStats *GetISteamUserStats( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   146 
   147 	// returns the ISteamGameServerStats interface
   148 	virtual ISteamGameServerStats *GetISteamGameServerStats( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   149 
   150 	// returns apps interface
   151 	virtual ISteamApps *GetISteamApps( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   152 
   153 	// networking
   154 	virtual ISteamNetworking *GetISteamNetworking( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   155 
   156 	// remote storage
   157 	virtual ISteamRemoteStorage *GetISteamRemoteStorage( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   158 
   159 	// user screenshots
   160 	virtual ISteamScreenshots *GetISteamScreenshots( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   161 
   162 
   163 	// this needs to be called every frame to process matchmaking results
   164 	// redundant if you're already calling SteamAPI_RunCallbacks()
   165 	virtual void RunFrame() = 0;
   166 
   167 	// returns the number of IPC calls made since the last time this function was called
   168 	// Used for perf debugging so you can understand how many IPC calls your game makes per frame
   169 	// Every IPC call is at minimum a thread context switch if not a process one so you want to rate
   170 	// control how often you do them.
   171 	virtual uint32 GetIPCCallCount() = 0;
   172 
   173 	// API warning handling
   174 	// 'int' is the severity; 0 for msg, 1 for warning
   175 	// 'const char *' is the text of the message
   176 	// callbacks will occur directly after the API function is called that generated the warning or message
   177 	virtual void SetWarningMessageHook( SteamAPIWarningMessageHook_t pFunction ) = 0;
   178 
   179 	// Trigger global shutdown for the DLL
   180 	virtual bool BShutdownIfAllPipesClosed() = 0;
   181 
   182 #ifdef _PS3
   183 	virtual ISteamPS3OverlayRender *GetISteamPS3OverlayRender() = 0;
   184 #endif
   185 
   186 	// Expose HTTP interface
   187 	virtual ISteamHTTP *GetISteamHTTP( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   188 
   189 	// Exposes the ISteamUnifiedMessages interface
   190 	virtual ISteamUnifiedMessages *GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0;
   191 
   192 };
   193 
   194 #define STEAMCLIENT_INTERFACE_VERSION		"SteamClient012"
   195 
   196 //-----------------------------------------------------------------------------
   197 // Purpose: Base values for callback identifiers, each callback must
   198 //			have a unique ID.
   199 //-----------------------------------------------------------------------------
   200 enum { k_iSteamUserCallbacks = 100 };
   201 enum { k_iSteamGameServerCallbacks = 200 };
   202 enum { k_iSteamFriendsCallbacks = 300 };
   203 enum { k_iSteamBillingCallbacks = 400 };
   204 enum { k_iSteamMatchmakingCallbacks = 500 };
   205 enum { k_iSteamContentServerCallbacks = 600 };
   206 enum { k_iSteamUtilsCallbacks = 700 };
   207 enum { k_iClientFriendsCallbacks = 800 };
   208 enum { k_iClientUserCallbacks = 900 };
   209 enum { k_iSteamAppsCallbacks = 1000 };
   210 enum { k_iSteamUserStatsCallbacks = 1100 };
   211 enum { k_iSteamNetworkingCallbacks = 1200 };
   212 enum { k_iClientRemoteStorageCallbacks = 1300 };
   213 enum { k_iSteamUserItemsCallbacks = 1400 };
   214 enum { k_iSteamGameServerItemsCallbacks = 1500 };
   215 enum { k_iClientUtilsCallbacks = 1600 };
   216 enum { k_iSteamGameCoordinatorCallbacks = 1700 };
   217 enum { k_iSteamGameServerStatsCallbacks = 1800 };
   218 enum { k_iSteam2AsyncCallbacks = 1900 };
   219 enum { k_iSteamGameStatsCallbacks = 2000 };
   220 enum { k_iClientHTTPCallbacks = 2100 };
   221 enum { k_iClientScreenshotsCallbacks = 2200 };
   222 enum { k_iSteamScreenshotsCallbacks = 2300 };
   223 enum { k_iClientAudioCallbacks = 2400 };
   224 enum { k_iClientUnifiedMessagesCallbacks = 2500 };
   225 enum { k_iSteamStreamLauncherCallbacks = 2600 };
   226 enum { k_iClientControllerCallbacks = 2700 };
   227 enum { k_iSteamControllerCallbacks = 2800 };
   228 enum { k_iClientParentalSettingsCallbacks = 2900 };
   229 enum { k_iClientDeviceAuthCallbacks = 3000 };
   230 enum { k_iClientNetworkDeviceManagerCallbacks = 3100 };
   231 
   232 
   233 //-----------------------------------------------------------------------------
   234 // The CALLBACK macros are for client side callback logging enabled with
   235 // log_callback <first callnbackID> <last callbackID>
   236 // Do not change any of these. 
   237 //-----------------------------------------------------------------------------
   238 
   239 class CSteamCallback
   240 {
   241 public:
   242 	virtual const char *GetCallbackName() const = 0;
   243 	virtual uint32 GetCallbackID() const = 0;
   244 	virtual uint8 *GetFixedData() const = 0;
   245 	virtual uint32 GetFixedSize() const = 0;
   246 	virtual uint32 GetNumMemberVariables() const = 0;
   247 	virtual bool GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize, uint32 &varCount, const char **pszName, const char **pszType  ) const = 0;
   248 };
   249 
   250 #define DEFINE_CALLBACK( callbackname, callbackid ) \
   251 struct callbackname##_t { \
   252 	enum { k_iCallback = callbackid }; \
   253 	static callbackname##_t *GetNullPointer() { return 0; }
   254 
   255 #define CALLBACK_MEMBER( varidx, vartype, varname ) \
   256 	public: vartype varname ; \
   257 	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
   258 			varOffset = (unsigned int)(size_t)&GetNullPointer()->varname; \
   259 			varSize = sizeof( vartype ); \
   260 			varCount = 1; \
   261 			*pszName = #varname; *pszType = #vartype; }
   262 
   263 #define CALLBACK_ARRAY( varidx, vartype, varname, varcount ) \
   264 	public: vartype varname [ varcount ]; \
   265 	static void GetMemberVar_##varidx( unsigned int &varOffset, unsigned int &varSize, uint32 &varCount, const char **pszName, const char **pszType ) { \
   266 	varOffset = (unsigned int)(size_t)&GetNullPointer()->varname[0]; \
   267 	varSize = sizeof( vartype ); \
   268 	varCount = varcount; \
   269 	*pszName = #varname; *pszType = #vartype; }
   270 
   271 
   272 #define END_CALLBACK_INTERNAL_BEGIN( callbackname, numvars )  }; \
   273 class C##callbackname : public CSteamCallback { \
   274 public: callbackname##_t m_Data; \
   275 	C##callbackname () { memset( &m_Data, 0, sizeof(m_Data) ); } \
   276 	virtual const char *GetCallbackName() const { return #callbackname; } \
   277 	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
   278 	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
   279 	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
   280 	virtual uint32  GetNumMemberVariables() const { return numvars; } \
   281 	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { \
   282 	switch ( index ) { default : return false;
   283 
   284 
   285 #define END_CALLBACK_INTERNAL_SWITCH( varidx ) case varidx : m_Data.GetMemberVar_##varidx( varOffset, varSize, varCount, pszName, pszType ); return true;
   286 
   287 #define END_CALLBACK_INTERNAL_END() }; }; };
   288 
   289 #define END_DEFINE_CALLBACK_0( callbackname )  }; \
   290 class C##callbackname : public CSteamCallback { \
   291 public: callbackname##_t m_Data; \
   292 	virtual const char *GetCallbackName() const { return #callbackname; } \
   293 	virtual uint32  GetCallbackID() const { return callbackname##_t::k_iCallback; } \
   294 	virtual uint32  GetFixedSize() const { return sizeof( m_Data ); } \
   295 	virtual uint8  *GetFixedData() const { return (uint8*)&m_Data; } \
   296 	virtual uint32  GetNumMemberVariables() const { return 0; } \
   297 	virtual bool    GetMemberVariable( uint32 index, uint32 &varOffset, uint32 &varSize,  uint32 &varCount, const char **pszName, const char **pszType ) const { return false; } \
   298 	}; \
   299 	
   300 
   301 #define END_DEFINE_CALLBACK_1( callbackname ) \
   302 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 1 ) \
   303 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   304 	END_CALLBACK_INTERNAL_END()
   305 
   306 #define END_DEFINE_CALLBACK_2( callbackname ) \
   307 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 2 ) \
   308 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   309 	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   310 	END_CALLBACK_INTERNAL_END()
   311 
   312 #define END_DEFINE_CALLBACK_3( callbackname ) \
   313 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 3 ) \
   314 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   315 	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   316 	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   317 	END_CALLBACK_INTERNAL_END()
   318 
   319 #define END_DEFINE_CALLBACK_4( callbackname ) \
   320 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 4 ) \
   321 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   322 	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   323 	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   324 	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   325 	END_CALLBACK_INTERNAL_END()
   326 
   327 
   328 #define END_DEFINE_CALLBACK_6( callbackname ) \
   329 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 6 ) \
   330 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   331 	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   332 	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   333 	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   334 	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
   335 	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
   336 	END_CALLBACK_INTERNAL_END()
   337 
   338 #define END_DEFINE_CALLBACK_7( callbackname ) \
   339 	END_CALLBACK_INTERNAL_BEGIN( callbackname, 7 ) \
   340 	END_CALLBACK_INTERNAL_SWITCH( 0 ) \
   341 	END_CALLBACK_INTERNAL_SWITCH( 1 ) \
   342 	END_CALLBACK_INTERNAL_SWITCH( 2 ) \
   343 	END_CALLBACK_INTERNAL_SWITCH( 3 ) \
   344 	END_CALLBACK_INTERNAL_SWITCH( 4 ) \
   345 	END_CALLBACK_INTERNAL_SWITCH( 5 ) \
   346 	END_CALLBACK_INTERNAL_SWITCH( 6 ) \
   347 	END_CALLBACK_INTERNAL_END()
   348 
   349 #endif // ISTEAMCLIENT_H