1 /******************************************************************************
*
* Palm Interactive Boardroom ( PIB )
* Handheld presentation tool using a networked projector as a display.
*
* This source code is based on default IDE source as well as royalty-free
* samples provided with the IDE. This file shell was generated by the Palm OS
* Developer Suite IDE.
*
* Other royalty-free source code from HelloNetLib.c ( provided by
* Palm at www.palmsource.com ) to send TCP and UDP traffic to an IP
* address + port number was modified significanlty in support of
* the PIB requirements.
*
* Programming environment: Palm OS Developer Suite
*
* Created by Scott Armstrong for UIUC CS-427 Group 30, Fall 2005
* based on UML and requirements outlined by Group 30 members.
*
* File: AppMain.cpp
*
* Notes:
* - This version is based on a C to C++ conversion.
* - As of now, only the GUI is updated.
* - This update mainly designed as a "Let everyone know what's going on
* with the GUI in C++.
*
* Version 4.0.0
* - Work on integrating "Transfer" function set ( Project )
* - "Connect" ( connect to network ) is automatically started on the device
* based on a network call - an interactive function will be integrated
* in future iterations.
* - Issues connecting the Button trigger event to the Transfer form
*
*****************************************************************************/
#include <PalmOS.h>
#include "AppResources.h"
#include "UIControl.h"
#include "NetworkControl.h"
/***********************************************************************
*
* Entry Points
*
***********************************************************************/
/***********************************************************************
*
* Internal Constants
*
***********************************************************************/
#define appFileCreator 'xPIB' // register your own at http://www.palmos.com/dev/creatorid/
#define appVersionNum 0x01
#define appPrefID 0x00
#define appPrefVersionNum 0x01
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
/***********************************************************************
*
* FUNCTION: MainFormDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS: command - menu item id
*
* RETURNED: nothing
*
* REVISION HISTORY: 4.0
*
*
***********************************************************************/
82 static Boolean MainFormDoCommand( UInt16 command )
{
bool handled = false;
FormType * pForm;
switch ( command ) {
case MainOptionsAboutStarterApp:
pForm = FrmInitForm( AboutForm );
FrmDoDialog( pForm ); // Display the About Box.
FrmDeleteForm( pForm );
handled = true;
break;
case MainOptionsSelectFileStarterApp:
pForm = FrmInitForm( SelectFileForm );
FrmDoDialog( pForm ); // Display the Select File Box.
FrmDeleteForm( pForm );
handled = true;
break;
case MainOptionsTransferSettingsStarterApp:
//pForm = FrmInitForm( MainTransferForm );
FrmGotoForm( MainTransferForm );
//FrmDoDialog( pForm ); // Display the Transfer Video Box.
//FrmDeleteForm( pForm );
handled = true;
break;
}
return handled;
}
114 static Boolean TransferFormHandleEvent( EventType* pEvent )
{
Boolean handled = false;
FormType* pForm;
switch( pEvent->eType )
{
case menuEvent:
return MainFormDoCommand( pEvent->data.menu.itemID );
case frmOpenEvent:
pForm = FrmGetActiveForm( );
FrmDrawForm( pForm );
handled = true;
break;
case ctlSelectEvent: //if a button was pressed
switch ( pEvent->data.ctlSelect.controlID )
{ //find which button and act accordingly
case MainSendOKButton:
FrmGotoForm( MainForm );
handled = true;
break;
case MainSendTCPButton:
break;
default:
break;
}
default:
break;
}
return handled;
}
/***********************************************************************
*
* FUNCTION: ConnectFormHandleEvent
*
* DESCRIPTION: This routine is the event handler for the
* "ConnectForm" of this application.
*
* PARAMETERS: pEvent - a pointer to an EventType structure
*
* RETURNED: true if the event has handle and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
*
*
***********************************************************************/
169 static Boolean ConnectFormHandleEvent( EventType* pEvent )
{ //event handler inside the ConnectForm
bool handled = false;
FormType* pForm;
switch( pEvent->eType )
{
case frmOpenEvent:
pForm = FrmGetActiveForm( );
FrmDrawForm( pForm );
handled = true;
break;
case ctlSelectEvent:
FrmGotoForm( MainForm );
handled = true;
break;
////////WILL NEED TO ADD MORE ONCE CONNECT DOES ITS THING
default:
break;
}
return handled;
}
/***********************************************************************
*
* FUNCTION: MainFormHandleEvent
*
* DESCRIPTION: This routine is the event handler for the
* "MainForm" of this application.
*
* PARAMETERS: pEvent - a pointer to an EventType structure
*
* RETURNED: true if the event has handle and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
*
*
***********************************************************************/
209 static Boolean MainFormHandleEvent( EventType* pEvent )
{
bool handled = false;
FormType* pForm;
switch ( pEvent->eType ) {
case menuEvent:
return MainFormDoCommand( pEvent->data.menu.itemID );
case frmOpenEvent:
pForm = FrmGetActiveForm( );
FrmDrawForm( pForm );
handled = true;
break;
//Here we look at which button was pressed in the mainForm
//the IDs are defined in AppResources.h
case ctlSelectEvent:
switch ( pEvent->data.ctlSelect.controlID )
{
case NavigateBackButton:
break;
case NavigateNextButton:
break;
case ConnectNetworkButton:
FrmGotoForm( ConnectForm );
break;
case TransferVideoButton:
break;
}
default:
break;
}
return handled;
}
/***********************************************************************
*
* FUNCTION: AppHandleEvent
*
* DESCRIPTION: This routine loads form resources and set the event
* handler for the form loaded.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event has handle and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
*
*
***********************************************************************/
267 static Boolean AppHandleEvent( EventType* pEvent )
{
UInt16 formId;
FormType* pForm;
bool handled = false;
if ( pEvent->eType == frmLoadEvent ) {
// Load the form resource.
formId = pEvent->data.frmLoad.formID;
pForm = FrmInitForm( formId );
FrmSetActiveForm( pForm );
// Set the event handler for the form. The handler of the currently
// active form is called by FrmHandleEvent each time is receives an
// event.
switch ( formId ) {
case MainForm:
FrmSetEventHandler( pForm, MainFormHandleEvent );
break;
case ConnectForm:
FrmSetEventHandler( pForm, ConnectFormHandleEvent );
break;
case MainTransferForm:
FrmSetEventHandler( pForm, TransferFormHandleEvent );
break;
default:
break;
}
handled = true;
}
return handled;
}
/***********************************************************************
*
* FUNCTION: AppStart
*
* DESCRIPTION: Get the current application's preferences.
*
* PARAMETERS: nothing
*
* RETURNED: Err value errNone if nothing went wrong
*
* REVISION HISTORY:
*
*
***********************************************************************/
318 static Err AppStart( void )
{
FrmGotoForm( MainForm );
return errNone;
}
/***********************************************************************
*
* FUNCTION: AppStop
*
* DESCRIPTION: Save the current state of the application.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
*
*
***********************************************************************/
339 static void AppStop( void )
{
// Close all the open forms.
FrmCloseAllForms( );
}
/***********************************************************************
*
* FUNCTION: AppEventLoop
*
* DESCRIPTION: This routine is the event loop for the application.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
*
*
***********************************************************************/
360 static void AppEventLoop( void )
{
Err error;
EventType event;
do {
EvtGetEvent( &event, evtWaitForever );
if ( SysHandleEvent( &event ) )
continue;
if ( MenuHandleEvent( 0, &event, &error ) )
continue;
if ( AppHandleEvent( &event ) )
continue;
FrmDispatchEvent( &event );
} while ( event.eType != appStopEvent );
}
/***********************************************************************
*
* FUNCTION: PilotMain
*
* DESCRIPTION: This is the main entry point for the application.
*
* PARAMETERS: cmd - word value specifying the launch code.
* cmdPB - pointer to a structure that is associated with the launch code.
* launchFlags - word value providing extra information about the launch.
* RETURNED: Result of launch
*
* REVISION HISTORY:
*
*
***********************************************************************/
398 UInt32 PilotMain( UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags )
{
Err error = errNone;
switch ( cmd ) {
case sysAppLaunchCmdNormalLaunch:
if ( ( error = AppStart( ) ) == 0 ) {
AppEventLoop( );
AppStop( );
}
break;
default:
break;
}
return error;
}
1 //
// Palm App Name: "AppMain.cpp" - Palm Interactive Boardroom ( PIB )
// "UIControl.cpp
//
// Filename: "AppResources.h"
//
// Palm App Version: "4.1.1"
// Resource: tFRM 1000
#define MainForm 1000
#define NavigateBackButton 1001
#define NavigateNextButton 1002
#define ConnectNetworkButton 1003
#define TransferVideoButton 1004 // Specify target IP and sends Video ( TCP )
// Resource: tFRM 1100
#define AboutForm 1100
#define AboutOKButton 1105
#define AboutTitleLabel 1102
#define AboutText1Label 1103
#define AboutText2Label 1104
// Resource: tFRM 1200
#define ConnectForm 1200 //( Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0 )
#define ConnectOKButton 1205 //( Left Origin = 58, Top Origin = 139, Width = 40, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard )
//#define ConnectTitleLabel 1202 //( Left Origin = 54, Top Origin = 25, Usable = 1, Font = Bold 12 )
//#define ConnectText1Label 1203 //( Left Origin = 23, Top Origin = 54, Usable = 1, Font = Standard )
//#define ConnectText2Label 1204 //( Left Origin = 50, Top Origin = 104, Usable = 1, Font = Bold )
// Resource: tFRM 1300
#define SelectFileForm 1300 //( Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0 )
#define SelectFileOKButton 1305 //( Left Origin = 58, Top Origin = 139, Width = 40, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard )
#define SelectFileInput 1302 //( Left Origin = 54, Top Origin = 25, Usable = 1, Font = Bold 12 )
#define SelectFileText1 1303 //( Left Origin = 23, Top Origin = 54, Usable = 1, Font = Standard )
//#define ConnectText2Label 1304 //( Left Origin = 50, Top Origin = 104, Usable = 1, Font = Bold )
// Resource: tFRM 1500
#define MainTransferForm 1500 //( Left Origin = 0, Top Origin = 0, Width = 160, Height = 160, Usable = 1, Modal = 0, Save Behind = 0, Help ID = 0, Menu Bar ID = 1000, Default Button ID = 0 )
#define MainSendTCPButton 1509 //( Left Origin = 4, Top Origin = 146, Width = 40, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard )
#define MainSendOKButton 1500 //( Left Origin = 49, Top Origin = 146, Width = 40, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard )
#define MainIP1Field 1521 //( Left Origin = 16, Top Origin = 20, Width = 17, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 3, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1 )
#define MainIP2Field 1522 //( Left Origin = 37, Top Origin = 20, Width = 17, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 3, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1 )
#define MainIP3Field 1523 //( Left Origin = 58, Top Origin = 20, Width = 17, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 3, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1 )
#define MainIP4Field 1524 //( Left Origin = 79, Top Origin = 20, Width = 17, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 3, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1 )
#define MainPortField 1525 //( Left Origin = 125, Top Origin = 20, Width = 32, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 5, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1 )
#define MainSysLibFindLabel 1501 //( Left Origin = 4, Top Origin = 35, Usable = 1, Font = Standard )
#define MainNetLibOpenLabel 1502 //( Left Origin = 4, Top Origin = 47, Usable = 1, Font = Standard )
#define MainNetLibOpenIFLabel 1503 //( Left Origin = 4, Top Origin = 59, Usable = 1, Font = Standard )
#define MainNetLibCloseLabel 1504 //( Left Origin = 4, Top Origin = 131, Usable = 1, Font = Standard )
#define MainSysLibFindResultLabel 1505 //( Left Origin = 125, Top Origin = 35, Usable = 1, Font = Standard )
#define MainNetLibOpenResultLabel 1506 //( Left Origin = 125, Top Origin = 47, Usable = 1, Font = Standard )
#define MainNetLibOpenIFResultLabel 1507 //( Left Origin = 125, Top Origin = 59, Usable = 1, Font = Standard )
#define MainNetLibCloseResultLabel 1508 //( Left Origin = 125, Top Origin = 131, Usable = 1, Font = Standard )
#define MainNetLibSocketOpenLabel 1510 //( Left Origin = 4, Top Origin = 71, Usable = 1, Font = Standard )
#define MainNetLibSocketOpenResultLabel 1511 //( Left Origin = 125, Top Origin = 71, Usable = 1, Font = Standard )
#define MainNetLibSocketConnectLabel 1512 //( Left Origin = 4, Top Origin = 83, Usable = 1, Font = Standard )
#define MainNetLibSocketConnectResultLabel 1513 //( Left Origin = 125, Top Origin = 83, Usable = 1, Font = Standard )
#define MainNetLibSendresultLabel 1514 //( Left Origin = 4, Top Origin = 95, Usable = 1, Font = Standard )
#define MainNetLibSendResultLabel 1515 //( Left Origin = 125, Top Origin = 95, Usable = 1, Font = Standard )
#define MainNetLibSocketCloseLabel 1516 //( Left Origin = 4, Top Origin = 119, Usable = 1, Font = Standard )
#define MainNetLibSocketCloseResultLabel 1517 //( Left Origin = 125, Top Origin = 119, Usable = 1, Font = Standard )
#define MainBytesSentLabel 1518 //( Left Origin = 4, Top Origin = 108, Usable = 1, Font = Standard )
#define MainBytesSentResultLabel 1519 //( Left Origin = 125, Top Origin = 107, Usable = 1, Font = Standard )
#define MainIPAddressLabel 1526 //( Left Origin = 4, Top Origin = 20, Usable = 1, Font = Standard )
#define MainDot1Label 1527 //( Left Origin = 34, Top Origin = 20, Usable = 1, Font = Standard )
#define MainDot2Label 1528 //( Left Origin = 55, Top Origin = 20, Usable = 1, Font = Standard )
#define MainDot3Label 1529 //( Left Origin = 76, Top Origin = 20, Usable = 1, Font = Standard )
#define MainPortLabel 1530 //( Left Origin = 103, Top Origin = 20, Usable = 1, Font = Standard )
// Resource: Talt 1000
#define NetErrorAlert 1000
#define NetErrorOK 0
// Resource: Talt 1002
#define InvalidDestAlert 1002
#define InvalidDestOK 0
// Resource: Talt 1001
#define RomIncompatibleAlert 1001
#define RomIncompatibleOK 0
// Resource: MBAR 1000
#define MainFormMenuBar 1000
// Resource: MENU 1000
#define MainOptionsMenu 1000
#define MainOptionsAboutStarterApp 1000
#define MainOptionsTransferSettingsStarterApp 1001
#define MainOptionsSelectFileStarterApp 1002
// Resource: MBAR 1100
#define SystemOptionsMenuBar 1100
// Resource: MENU 1100
#define SystemOptionsMenu 1100 // MENU
#define SystemOptionsConnect 1100 // ( item )
// Resource: PICT 1001
#define Bitmap 1001
// Resource: PICT 1002
#define Bitmap2 1002
// Resource: PICT 1008
#define Bitmap3 1008
// Resource: PICT 1011
#define Bitmap4 1011
// Resource: PICT 1012
#define Bitmap5 1012
// Resource: PICT 1018
#define Bitmap6 1018
// Resource: taif 1000
#define Largeicons12and8bitsAppIconFamily 1000
// Resource: taif 1001
#define Smallicons12and8bitsAppIconFamily 1001
1 #ifndef NETWORKCONTROL_H
#define NETWORKCONTROL_H
#include <PalmOS.h>
#include "UIControl.h"
#include <INetMgr.h> // For managing device network settings
#include "AppResources.h"
8 class NetworkControl
{
public:
11 NetworkControl( UIControl* GUI_Assignment );
////sendTCP( ) NEEDS TO BE FIXED BY THE AUTHOR
/// I cannot get it to compile. -Adam
15 void SendTCP( void );
//void SendUDP( void ); // Currently only using TCP - possible future
// UDP implementation
private:
19 UIControl* User_Interface;
};
1 // --------------------------------------------------------------------------
/*
To build a multi-section application
1. In makefile, set MULTIPLE_CODE_SECTIONS = TRUE
2. Edit Sections.def to specify the number of code sections desired
3. Modify this file to match the code sections
( Sections.def and this file are set up with 2 extra sections
by default. )
4. Include this file in project sources.
5. Annotate each function with a section define like so:
void DoWork( ) EXTRA_SECTION_ONE;
void DrawForm( ) EXTRA_SECTION_TWO;
Notice that the annotations need to be visible at the function
definition, and everywhere the function is used. Any function
without an annotation will go into the default code section.
To effectively disable the multi-section annotations,
just define these section macros to expand to nothing.
Be sure to follow the instructions and warnings given at:
http://prc-tools.sourceforge.net/doc/prc-tools_3.html#SEC17
*/
// --------------------------------------------------------------------------
#ifndef _SECTIONS_H
#define _SECTIONS_H
#define EXTRA_SECTION_ONE __attribute__ ( ( section ( "code1" ) ) )
#define EXTRA_SECTION_TWO __attribute__ ( ( section ( "code2" ) ) )
#endif
1 #include "UIControl.h"
#include "AppResources.h"
/***********************************************************************
*
* Internal Structures
*
***********************************************************************/
typedef struct
{
NetIPAddr addr;
UInt16 port;
} NetLibPreferenceType;
/***********************************************************************
*
* Globals
*
***********************************************************************/
NetLibPreferenceType gPrefs = {};
const UInt16 bufLen = 16;
char buf[16] = "testing 1-2\n";
26 void UIControl::ShowResult( UInt16 id, Err error )
{
char resultString[11];
FormType *formPtr;
UInt16 objIndex;
// Prepare the result as a string
switch ( error ){
case CLEAR_RESULT:
StrCopy( resultString, " " );
break;
case PROCESSING_RESULT:
StrCopy( resultString, " .... " ); // indicates no results yet
break;
default:
StrPrintF( resultString, "0x%04X", error );
break;
}
// Update the specified field label
formPtr = FrmGetFormPtr( MainForm );
objIndex = FrmGetObjectIndex( formPtr, id );
FrmHideObject( formPtr, objIndex );
FrmCopyLabel( formPtr, id, resultString );
FrmShowObject( formPtr, objIndex );
}
53 void UIControl::ClearResults( void )
{
ShowResult( MainSysLibFindResultLabel, -1 );
ShowResult( MainNetLibOpenResultLabel, -1 );
ShowResult( MainNetLibOpenIFResultLabel, -1 );
ShowResult( MainNetLibSocketOpenResultLabel, -1 );
ShowResult( MainNetLibSocketConnectResultLabel, -1 );
ShowResult( MainNetLibSendResultLabel, -1 );
ShowResult( MainBytesSentResultLabel, -1 );
ShowResult( MainNetLibSocketCloseResultLabel, -1 );
ShowResult( MainNetLibCloseResultLabel, -1 );
}
66 bool UIControl::GetValue( UInt16 objID, Int32 *valueP )
{
FormType *formPtr;
UInt16 objIndex;
FieldType *fieldPtr;
Char *text;
formPtr = FrmGetFormPtr( MainForm );
if ( !formPtr ) return false;
objIndex = FrmGetObjectIndex( formPtr, objID );
fieldPtr = ( FieldType* )FrmGetObjectPtr( formPtr, objIndex );
if ( !fieldPtr ) return false;
text = FldGetTextPtr( fieldPtr );
if ( !text ) return false;
*valueP = StrAToI( text );
return true;
}
86 bool UIControl::SetValue( UInt16 objID, Int32 value )
{
FormType *formPtr;
UInt16 objIndex;
FieldType *fieldPtr;
MemHandle h, oldHandle;
char * text;
formPtr = FrmGetFormPtr( MainForm );
if ( !formPtr ) return false;
objIndex = FrmGetObjectIndex( formPtr, objID );
fieldPtr = ( FieldType* )FrmGetObjectPtr( formPtr, objIndex );
if ( !fieldPtr ) return false;
if ( MainPortField == objID ) {
h = MemHandleNew( 6 );
} else {
h = MemHandleNew( 4 );
}
if ( !h ) return false;
text = ( char * )MemHandleLock( h );
if ( MainPortField == objID ) {
StrPrintF( text, "%u", ( UInt16 )value );
} else {
StrPrintF( text, "%u", ( UInt8 )value );
}
MemHandleUnlock( h );
oldHandle = FldGetTextHandle( fieldPtr );
FldSetTextHandle( fieldPtr, h );
if ( oldHandle ) MemHandleFree( oldHandle );
return true;
}
122 bool UIControl::GetAddr( UInt16 AppNetRefnum, NetIPAddr *addrP, UInt16 *portP )
{
UInt8 i;
Int32 ip[4];
Int32 port;
Char textIP[16];
// Get the values
for ( i = 0; i < 4; i++ ) {
if ( !GetValue( MainIP1Field + i, &( ip[i] ) ) ||
ip[i] > 255 ||
ip[i] < 0 ) {
return false;
}
}
if ( !GetValue( MainPortField, &port ) ||
port > 65535 ||
port < 1 ) {
return false;
}
StrPrintF( textIP, "%u.%u.%u.%u", ( UInt8 )ip[0], ( UInt8 )ip[1], ( UInt8 )ip[2], ( UInt8 )ip[3] );
*addrP = NetLibAddrAToIN( AppNetRefnum, textIP );
*portP = ( UInt16 )port;
return true;
}
150 void UIControl::SendTCP( void )
{
Err error;
UInt16 AppNetRefnum;
UInt16 ifErrs;
NetSocketRef socket;
Int16 result;
NetSocketAddrINType destAddr;
// const UInt16 bufLen = 15; // using global variables for now
// char buf[bufLen] = "xxxxxx\n"; // will need to substitute a file
// wrapped for TCP/IP to be received
// and used as a video signal
UInt16 sentBytes = 0;
ClearResults( );
// Find the network library and start tne network connection ( Connect function )
ShowResult( MainSysLibFindResultLabel, PROCESSING_RESULT );
error = SysLibFind( "Net.lib", &AppNetRefnum );
ShowResult( MainSysLibFindResultLabel, error );
if ( error ) return;
// Get and validate the destination
if ( !GetAddr( AppNetRefnum, &gPrefs.addr, &gPrefs.port ) ) {
FrmAlert( InvalidDestAlert );
return;
}
// Open the network library
ShowResult( MainNetLibOpenResultLabel, PROCESSING_RESULT );
ShowResult( MainNetLibOpenIFResultLabel, PROCESSING_RESULT );
error = NetLibOpen( AppNetRefnum, &ifErrs );
ShowResult( MainNetLibOpenResultLabel, error );
ShowResult( MainNetLibOpenIFResultLabel, ifErrs );
if ( ifErrs || ( error && error != netErrAlreadyOpen ) ) goto CloseNetLib;
// Open a socket
ShowResult( MainNetLibSocketOpenResultLabel, PROCESSING_RESULT );
socket = NetLibSocketOpen( AppNetRefnum, // Network library
netSocketAddrINET, // Address domain
netSocketTypeStream, // Socket type
netSocketProtoIPTCP, // Protocol
-1, // Timeout
&error // Error result
);
ShowResult( MainNetLibSocketOpenResultLabel, error );
if ( error ) goto CloseNetLib;
// Connect the socket to its destination
MemSet( &destAddr, sizeof( destAddr ), 0 );
destAddr.family = netSocketAddrINET; // This should match the second argument to NetLibSocketOpen
destAddr.port = gPrefs.port;
destAddr.addr = gPrefs.addr;
error = 0;
ShowResult( MainNetLibSocketConnectResultLabel, PROCESSING_RESULT );
result = NetLibSocketConnect( AppNetRefnum, // Network library
socket, // Socket reference
( NetSocketAddrType* )&destAddr, // Destination address
sizeof( destAddr ), // Length of destAddr
-1, // Timeout
&error // Error result
);
if ( result == -1 ) {
ShowResult( MainNetLibSocketConnectResultLabel, error );
goto CloseSocket;
} else {
ShowResult( MainNetLibSocketConnectResultLabel, 0 );
}
// Send data
ShowResult( MainBytesSentResultLabel, PROCESSING_RESULT );
while ( sentBytes < bufLen ) {
ShowResult( MainNetLibSendResultLabel, PROCESSING_RESULT );
result = NetLibSend ( AppNetRefnum, // Network library
socket, // Socket reference
buf + sentBytes, // Buffer to send
bufLen - sentBytes, // Bytes to send from buffer
0, // Flags
NULL, // Destination address -- does not apply to TCP sockets
0, // Length of destination address
-1, // Timeout
&error // Error result
);
if ( result == -1 ) {
ShowResult( MainNetLibSendResultLabel, error );
goto CloseSocket;
}
sentBytes += result;
ShowResult( MainBytesSentResultLabel, sentBytes );
}
ShowResult( MainNetLibSendResultLabel, 0 );
// Close the socket
CloseSocket:
ShowResult( MainNetLibSocketCloseResultLabel, PROCESSING_RESULT );
result = NetLibSocketClose ( AppNetRefnum, // Network Library
socket, // Socket reference
-1, // Timeout
&error // Error result
);
if ( result == -1 ) {
ShowResult( MainNetLibSocketCloseResultLabel, error );
} else {
ShowResult( MainNetLibSocketCloseResultLabel, 0 );
}
// Close the network library
CloseNetLib:
ShowResult( MainNetLibCloseResultLabel, PROCESSING_RESULT );
error = NetLibClose( AppNetRefnum, false );
ShowResult( MainNetLibCloseResultLabel, error );
1 #ifndef UICONTROL_H
#define UICONTROL_H
#include <PalmOS.h>
#define CLEAR_RESULT -1
#define PROCESSING_RESULT -2
8 class UIControl
{
public:
/***********************************************************************
*
* FUNCTION: ShowResult ( part of Transfer / Project )
*
* DESCRIPTION: This routine updates the UI to show the results of each
* of the function calls involved in the current network
* operation.
* This information should be streamlined or possibly removed
* from the UI as we approach the final PIB releases.
* This is valuable information for testing and debugging for now.
*
* PARAMETERS: id - ID of the label to update
* error - error code returned by the corresponding
* function. If this is -1 the result is cleared
*
* RETURNED: none
* *
***********************************************************************/
30 void ShowResult( UInt16 id, Err error );
/***********************************************************************
*
* FUNCTION: ClearResults
*
* DESCRIPTION: This routine clears all the results listed on the main
* form.
*
* PARAMETERS: none
*
* RETURNED: none
*
***********************************************************************/
44 void ClearResults( void );
/***********************************************************************
*
* FUNCTION: GetValue
*
* DESCRIPTION: This routine gets the numeric value of the specified
* text field.
*
* PARAMETERS: objID - ID of the field on the main form
* valueP - pointer to memory where value is returned
*
* RETURNED: True if successful, false otherwise.
*
***********************************************************************/
59 bool GetValue( UInt16 objID, Int32 *valueP );
/***********************************************************************
*
* FUNCTION: SetValue
*
* DESCRIPTION: This routine sets the numeric value of the specified
* text field.
*
* PARAMETERS: objID - ID of the field on the main form
* value - the value to insert
*
* RETURNED: True if successful, false otherwise.
*
* NOTES: Determines the maximum length to use based upon the ID
*
***********************************************************************/
76 bool SetValue( UInt16 objID, Int32 value );
/***********************************************************************
*
* FUNCTION: GetAddr
*
* DESCRIPTION: This routine gets the IP address and port that the user
* has entered.
*
* PARAMETERS: AppNetRefnum - Reference number of NetLib
* addrP - pointer to memory where address is
* returned
* portP - pointer to memory where port is
* returned
*
* RETURNED: True if the IP address and port are valid, false
* otherwise.
*
* NOTES: The only check peformed is to see whether the values
* are in the appropriate numeric ranges. This doesn't
* check whether the specified host exists or is listening
* on the specified port.
* If host is not found, the system stops processing and
* pauses until a timeout period.
* - Future releases should include a "host not found" check.
*
***********************************************************************/
103 bool GetAddr( UInt16 AppNetRefnum, NetIPAddr *addrP, UInt16 *portP );
105 void SendTCP( void );
private:
};