extensions/clientprefs/query.h
author Matt Woodrow <pred@alliedmods.net>
Thu Feb 19 19:28:50 2009 +1300 (2009-02-19)
changeset 2592 e69a1297edbc
parent 2380 422da6951d47
child 3804 90159516acd3
permissions -rw-r--r--
Upgraded clientprefs to use the client serial API (bug 3616)
pred@2009
     1
/**
pred@2009
     2
 * vim: set ts=4 :
pred@2009
     3
 * =============================================================================
pred@2009
     4
 * SourceMod Client Preferences Extension
pred@2009
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2009
     6
 * =============================================================================
pred@2009
     7
 *
pred@2009
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2009
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009
    10
 * Free Software Foundation.
pred@2009
    11
 * 
pred@2009
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2009
    15
 * details.
pred@2009
    16
 *
pred@2009
    17
 * You should have received a copy of the GNU General Public License along with
pred@2009
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2009
    19
 *
pred@2009
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2009
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2009
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2009
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2009
    28
 *
pred@2009
    29
 * Version: $Id$
pred@2009
    30
 */
pred@2009
    31
pred@2009
    32
#ifndef _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
pred@2009
    33
#define _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
pred@2009
    34
pred@2009
    35
#include "extension.h"
pred@2009
    36
#include "cookie.h"
pred@2009
    37
#include "sh_string.h"
pred@2009
    38
pred@2009
    39
enum querytype
pred@2009
    40
{
pred@2009
    41
	Query_InsertCookie = 0,
pred@2009
    42
	Query_SelectData,
pred@2009
    43
	Query_InsertData,
pred@2048
    44
	Query_SelectId,
pred@2207
    45
	Query_Connect,
pred@2207
    46
};
pred@2207
    47
pred@2207
    48
struct Cookie;
pred@2207
    49
struct CookieData;
pred@2207
    50
#define MAX_NAME_LENGTH 30
pred@2207
    51
pred@2207
    52
/* This stores all the info required for our param binding until the thread is executed */
pred@2207
    53
struct ParamData
pred@2207
    54
{
pred@2207
    55
	ParamData();
pred@2207
    56
pred@2207
    57
	~ParamData();
pred@2207
    58
pred@2207
    59
	/* Contains a name, description and access for InsertCookie queries */
pred@2207
    60
	Cookie *cookie;
pred@2207
    61
	/* A clients steamid - Used for most queries - Doubles as storage for the cookie name*/
pred@2207
    62
	char steamId[MAX_NAME_LENGTH];
pred@2207
    63
pred@2207
    64
	int cookieId;
pred@2207
    65
	CookieData *data;
pred@2009
    66
};
pred@2009
    67
pred@2009
    68
class TQueryOp : public IDBThreadOperation
pred@2009
    69
{
pred@2009
    70
public:
pred@2592
    71
	TQueryOp(enum querytype type, int serial);
pred@2207
    72
	TQueryOp(enum querytype type, Cookie *cookie);
pred@2009
    73
	~TQueryOp() {}
pred@2009
    74
pred@2009
    75
	IDBDriver *GetDriver();
pred@2009
    76
	IdentityToken_t *GetOwner();
pred@2009
    77
pred@2207
    78
	void SetDatabase(IDatabase *db);
pred@2207
    79
pred@2009
    80
	void Destroy();
pred@2009
    81
pred@2009
    82
	void RunThreadPart();
pred@2009
    83
	/* Thread has been cancelled due to driver unloading. Nothing else to do? */
pred@2207
    84
	void CancelThinkPart()	{}
pred@2009
    85
	void RunThinkPart();
pred@2009
    86
pred@2207
    87
	bool BindParamsAndRun();
pred@2207
    88
pred@2207
    89
	/* Params to be bound */
pred@2207
    90
	ParamData m_params;
pred@2207
    91
dvander@2359
    92
	inline IDatabase *GetDB()
dvander@2359
    93
	{
dvander@2359
    94
		return m_database;
dvander@2359
    95
	}
dvander@2359
    96
pred@2009
    97
private:
pred@2207
    98
	IDatabase *m_database;
dvander@2373
    99
	IQuery *m_pResult;
pred@2207
   100
pred@2207
   101
	/* Query type */
pred@2009
   102
	enum querytype m_type;
pred@2207
   103
pred@2207
   104
	/* Data to be passed to the callback */
pred@2592
   105
	int m_serial;
pred@2009
   106
	int m_insertId;
pred@2207
   107
	Cookie *m_pCookie;
pred@2009
   108
};
pred@2009
   109
pred@2009
   110
pred@2009
   111
#endif // _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_