1 /*---------------------------------------------------------------------------*
2   Project:  RevolutionDWC Demos
3   File:     ./common/src/d_net_connect.c
4 
5   Copyright 2005-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 #include "include/d_net_connect.h"
14 #include "include/common.h"
15 
16 #include <revolution.h>
17 #include <revolution/so.h>
18 #include <revolution/ncd.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 extern void*    AllocFunc( DWCAllocType name, u32   size, int align );
23 extern void     FreeFunc( DWCAllocType name, void* ptr,  u32 size  );
24 
25 static struct
26 {
27     u32     total;
28     u32     max;
29 }
30 s_memusage = {0,0};
31 
32 /*-------------------------------------------------------------------------*
33   Name:         _Alloc
34   Description:  Memory allocation
35  *-------------------------------------------------------------------------*/
_Alloc(u32 i_name,s32 i_size)36 static void* _Alloc(u32 i_name, s32 i_size)
37 {
38     s_memusage.total += i_size;
39 
40     if ( s_memusage.max < s_memusage.total )
41         s_memusage.max = s_memusage.total;
42 
43     return AllocFunc( (DWCAllocType)i_name, (u32)i_size, 32 );
44 }
45 
46 /*-------------------------------------------------------------------------*
47   Name:         _Free
48   Description:  Memory deallocation
49   *-------------------------------------------------------------------------*/
_Free(u32 i_name,void * o_memory_p,s32 i_size)50 static void _Free(u32 i_name, void* o_memory_p, s32 i_size)
51 {
52     s_memusage.total -= i_size;
53 
54     FreeFunc( (DWCAllocType)i_name, o_memory_p, (u32)i_size );
55 }
56 
57 /*-------------------------------------------------------------------------*
58   Name:         dNetConnect_Start
59 
60   Description:  Communication settings
61  *-------------------------------------------------------------------------*/
dNetConnect_Start()62 BOOL dNetConnect_Start()
63 {
64     s32 rc;
65 
66     /* Start the SO library */
67     OSReport( "SOInit() " );
68     {
69         SOLibraryConfig soLibConfig;
70 
71         (void)memset(&soLibConfig, 0, sizeof(soLibConfig));
72         soLibConfig.alloc = _Alloc;
73         soLibConfig.free  = _Free;
74 
75         rc = SOInit(&soLibConfig);
76         if ( rc != SO_SUCCESS )
77         {
78             OSReport( "failed (%d)\n", rc );
79             return FALSE;
80         }
81     }
82     OSReport( "success\n" );
83     /* Start the SO library */
84     OSReport( "SOStartup() " );
85     rc = SOStartup();
86     if ( rc != SO_SUCCESS )
87     {
88         OSReport( "failed (%d)\n", rc );
89         return FALSE;
90     }
91     OSReport( "success\n" );
92 
93     return TRUE;
94 }
95 
96 /*-------------------------------------------------------------------------*
97   Name:         dNetConnect_Finish
98 
99   Description:  End communication
100  *-------------------------------------------------------------------------*/
dNetConnect_Finish()101 void dNetConnect_Finish()
102 {
103     (void)SOCleanup();
104     (void)SOFinish();
105 
106     OSReport( "-------------------------------\n" );
107     OSReport( "SO memory usage MAX:%d\n", s_memusage.max );
108     OSReport( "-------------------------------\n" );
109 }
110 
111