2005-09-19 06:34:51 +02:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 2005 by Eric House (xwords@eehouse.org). All rights reserved.
|
2005-09-19 06:34:51 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "permid.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-12-30 06:13:30 +01:00
|
|
|
#include <stdlib.h>
|
2005-10-28 11:20:51 +02:00
|
|
|
#include <assert.h>
|
2005-09-19 06:34:51 +02:00
|
|
|
#include "mlock.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER;
|
2005-10-01 18:33:45 +02:00
|
|
|
string PermID::s_serverName;
|
2009-03-10 13:52:17 +01:00
|
|
|
int PermID::s_nextId = 0;
|
2009-09-26 16:05:51 +02:00
|
|
|
time_t PermID::s_startTime;
|
2005-09-19 06:34:51 +02:00
|
|
|
|
|
|
|
string
|
|
|
|
PermID::GetNextUniqueID()
|
|
|
|
{
|
|
|
|
MutexLock ml( &s_guard );
|
2005-10-01 18:33:45 +02:00
|
|
|
|
2009-03-10 13:52:17 +01:00
|
|
|
char buf[64];
|
2009-09-26 16:05:51 +02:00
|
|
|
snprintf( buf, sizeof(buf), "%s:%x:%d", s_serverName.c_str(),
|
|
|
|
(unsigned int)s_startTime, ++s_nextId );
|
2009-03-10 13:52:17 +01:00
|
|
|
string s(buf);
|
2005-09-19 06:34:51 +02:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2005-10-01 18:33:45 +02:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
PermID::SetServerName( const char* name )
|
|
|
|
{
|
|
|
|
s_serverName = name;
|
|
|
|
}
|
2005-10-23 23:06:07 +02:00
|
|
|
|
|
|
|
/* static */ void
|
2009-03-10 13:52:17 +01:00
|
|
|
PermID::SetStartTime( time_t startTime )
|
2005-10-23 23:06:07 +02:00
|
|
|
{
|
2009-09-26 16:05:51 +02:00
|
|
|
s_startTime = startTime;
|
|
|
|
logf( XW_LOGINFO, "assigned startTime: %ld", s_startTime );
|
2005-10-23 23:06:07 +02:00
|
|
|
}
|