1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Common code for GameSpy samples
// Note: This code is not intended to be used in a retail program
//
// Portions taken from PS3 sample applications. Please refer to Sony
// documentation and samples for application startup procedures.
#include <cell/sysmodule.h>
#include <netex/net.h>
#include <netex/libnetctl.h>
#include <sysutil/sysutil_common.h>
#include "../gsPlatform.h"
#include "../gsPlatformUtil.h"
#include "../gsMemory.h"
// entry point for GameSpy samples
extern int test_main(int argc, char ** argp);
#define PRIO (1001)
#define HOST_NAME "localhost"
// * added due to PS3 SDK 092.00x and above - all stub libraries require you to load the module
// * for it to be properly linked
gsi_bool _LoadModules()
{
cellSysmoduleInitialize();
if (cellSysmoduleLoadModule(CELL_SYSMODULE_NET) != CELL_OK)
{
printf("cellSysmoduleLoadModule(CELL_SYSMODULE_NET) failed\n");
return gsi_false;
}
if (cellSysmoduleLoadModule(CELL_SYSMODULE_IO) != CELL_OK)
{
printf("cellSysmoduleLoadModule(CELL_SYSMODULE_IO) failed\n");
return gsi_false;
}
if (cellSysmoduleLoadModule(CELL_SYSMODULE_USBD) != CELL_OK)
{
printf("cellSysmoduleLoadModule(CELL_SYSMODULE_USBD) failed\n");
return gsi_false;
}
if (cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_NP) != CELL_OK)
{
printf("cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_NP) failed\n");
return gsi_false;
}
if (cellSysmoduleLoadModule(CELL_SYSMODULE_RTC) != CELL_OK)
{
printf("cellSysmoduleLoadModule(CELL_SYSMODULE_RTC) failed\n");
return gsi_false;
}
return gsi_true;
}
// unloads modules to free up memory
void _UnloadModules()
{
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
cellSysmoduleUnloadModule(CELL_SYSMODULE_IO);
cellSysmoduleUnloadModule(CELL_SYSMODULE_USBD);
cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_NP);
cellSysmoduleUnloadModule(CELL_SYSMODULE_RTC);
cellSysmoduleFinalize();
}
gsi_bool _NetworkInit()
{
int r = sys_net_initialize_network();
if (r!=CELL_OK)
{
printf("ccNetworkInitializeNetwork: sys_net_initialize_network() failed: %i\n",r);
return gsi_false;
}
return (r==0);
}
gsi_bool _NetworkStart()
{
int iReturn, iNetworkState;
/*iReturn = cellSysutilInit();
if (iReturn < 0)
{
printf("cellSysutilInit() failed(%x)\n", iReturn);
return gsi_false;
}*/
iReturn = cellNetCtlInit();
if (iReturn!=CELL_OK)
{
printf("ccNetworkInitializeNetwork: cellNetCtlInit() failed: %i\n",
iReturn);
return gsi_false;
}
while (1)
{
iReturn=cellNetCtlGetState(&iNetworkState);
if (iReturn!=CELL_OK)
{
printf("ccNetworkInitializeNetwork: cellNetCtlGetState() failed: %i\n",
iReturn);
return gsi_false;
}
if (iNetworkState!=CELL_NET_CTL_STATE_IPObtained)
{
sys_timer_usleep(100 * 1000);
}
else
{
break;
}
};
return gsi_true;
}
void _NetworkStop()
{
cellNetCtlTerm();
//cellSysutilShutdown();
}
void _NetworkClose()
{
sys_net_finalize_network();
}
void * gsiMemManagedInit()
{
// Init the GSI memory manager (optional - for limiting GSI mem usage)
#if defined GSI_MEM_MANAGED
#define aMemoryPoolSize (1024*1024*8)
char *aMemoryPool = calloc(aMemoryPoolSize,32);
if(aMemoryPool == NULL)
{
printf("Failed to create memory pool - aborting\r\n");
return NULL;
}
else
{
gsMemMgrContext c = gsMemMgrCreate(gsMemMgrContext_Default, "Default",aMemoryPool, aMemoryPoolSize);
GSI_UNUSED(c);
}
return aMemoryPool;
#else
return NULL;
#endif
}
void gsiMemManagedClose(void * aMemoryPool)
{
#if defined(GSI_MEM_MANAGED)
// Optional - Dump memory leaks
gsi_u32 MemAvail = gsMemMgrMemAvailGet (gsMemMgrContext_Default);
gsi_u32 MemUsed = gsMemMgrMemUsedGet (gsMemMgrContext_Default);
gsi_u32 HwMark = gsMemMgrMemHighwaterMarkGet (gsMemMgrContext_Default);
printf("MemAvail %u: MemUsed%u MemHWMark %u\n", MemAvail,MemUsed,HwMark);
gsMemMgrDumpStats();
gsMemMgrDumpAllocations();
gsMemMgrValidateMemoryPool();
gsMemMgrDestroy(gsMemMgrContext_Default);
free(aMemoryPool);
#endif
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char ** argp)
{
//sys_pid_t pid = 0;
//int result = 0;
//int count = 0;
//int id_list[10];
//int i=0;
void *heap;
printf("\nGameSpy Test App Initializing\n"
"----------------------------------\n");
/*
// spawn IO module
if (sys_process_spawn(&pid, "brio.elf", NULL, 0, PRIO, 0) != SUCCEEDED) {
printf("sys_process_spawn(brio.elf) failed\n");
return (0);
}
*/
// load required modules
if(!_LoadModules())
{
printf("_LoadModules() failed\n");
return (0);
}
// initialize network using hardcoded settings above
if(!_NetworkInit())
{
printf("_NetworkInit() failed\n");
return (0);
}
if(!_NetworkStart())
{
printf("_NetworkStart() failed\n");
return (0);
}
heap = gsiMemManagedInit();
// start the actual program
printf("\nGameSpy Test App Starting\n"
"----------------------------------\n");
test_main(argc, argp);
// do any needed cleanup
printf("\nGameSpy Test App Exiting\n"
"----------------------------------\n");
gsiMemManagedClose(heap);
// close network
_NetworkStop();
_NetworkClose();
// unload modules
_UnloadModules();
// don't exit into never never land and lose our tty output.
while(1)
{
msleep(100);
}
return 0;
}
|