Line data Source code
1 : /* 2 : * PeerTalk Version and Utility Functions 3 : */ 4 : 5 : #include "peertalk.h" 6 : #include "pt_types.h" 7 : #include "pt_internal.h" 8 : 9 : /* ========================================================================== */ 10 : /* Version Information */ 11 : /* ========================================================================== */ 12 : 13 333 : const char *PeerTalk_Version(void) 14 : { 15 333 : return PT_VERSION_STRING; 16 : } 17 : 18 : /* ========================================================================== */ 19 : /* Error Strings */ 20 : /* ========================================================================== */ 21 : 22 46 : const char *PeerTalk_ErrorString(PeerTalk_Error error) 23 : { 24 46 : switch (error) { 25 3 : case PT_OK: 26 3 : return "Success"; 27 : 28 : /* Parameter & State Errors */ 29 3 : case PT_ERR_INVALID_PARAM: 30 3 : return "Invalid parameter"; 31 2 : case PT_ERR_NO_MEMORY: 32 2 : return "Out of memory"; 33 2 : case PT_ERR_NOT_INITIALIZED: 34 2 : return "Not initialized"; 35 1 : case PT_ERR_ALREADY_INITIALIZED: 36 1 : return "Already initialized"; 37 2 : case PT_ERR_INVALID_STATE: 38 2 : return "Invalid state"; 39 1 : case PT_ERR_NOT_SUPPORTED: 40 1 : return "Not supported on this platform"; 41 : 42 : /* Network Errors */ 43 2 : case PT_ERR_NETWORK: 44 2 : return "Network error"; 45 2 : case PT_ERR_TIMEOUT: 46 2 : return "Operation timed out"; 47 2 : case PT_ERR_CONNECTION_REFUSED: 48 2 : return "Connection refused"; 49 2 : case PT_ERR_CONNECTION_CLOSED: 50 2 : return "Connection closed"; 51 1 : case PT_ERR_NO_NETWORK: 52 1 : return "No network available"; 53 1 : case PT_ERR_NOT_CONNECTED: 54 1 : return "Not connected"; 55 1 : case PT_ERR_WOULD_BLOCK: 56 1 : return "Operation would block"; 57 : 58 : /* Buffer & Queue Errors */ 59 2 : case PT_ERR_BUFFER_FULL: 60 2 : return "Buffer full"; 61 1 : case PT_ERR_QUEUE_EMPTY: 62 1 : return "Queue empty"; 63 1 : case PT_ERR_MESSAGE_TOO_LARGE: 64 1 : return "Message too large"; 65 1 : case PT_ERR_BACKPRESSURE: 66 1 : return "Send backpressure (slow peer)"; 67 : 68 : /* Peer Errors */ 69 2 : case PT_ERR_PEER_NOT_FOUND: 70 2 : return "Peer not found"; 71 1 : case PT_ERR_DISCOVERY_ACTIVE: 72 1 : return "Discovery already active"; 73 : 74 : /* Protocol Errors (Phase 2) */ 75 2 : case PT_ERR_CRC: 76 2 : return "CRC validation failed"; 77 2 : case PT_ERR_MAGIC: 78 2 : return "Invalid magic number"; 79 1 : case PT_ERR_TRUNCATED: 80 1 : return "Truncated message"; 81 2 : case PT_ERR_VERSION: 82 2 : return "Protocol version mismatch"; 83 1 : case PT_ERR_NOT_POWER2: 84 1 : return "Size must be power of 2"; 85 : 86 : /* Operation Errors (continued) */ 87 0 : case PT_ERR_BUSY: 88 0 : return "Resource busy"; 89 0 : case PT_ERR_CANCELLED: 90 0 : return "Operation cancelled"; 91 0 : case PT_ERR_RATE_LIMITED: 92 0 : return "Rate limited - peer under pressure"; 93 : 94 : /* System Errors */ 95 1 : case PT_ERR_PLATFORM: 96 1 : return "Platform-specific error"; 97 1 : case PT_ERR_RESOURCE: 98 1 : return "Resource exhausted"; 99 1 : case PT_ERR_INTERNAL: 100 1 : return "Internal error"; 101 : 102 2 : default: 103 2 : return "Unknown error"; 104 : } 105 : } 106 : 107 : /* ========================================================================== */ 108 : /* Available Transports */ 109 : /* ========================================================================== */ 110 : 111 2 : uint16_t PeerTalk_GetAvailableTransports(void) 112 : { 113 2 : uint16_t transports = 0; 114 : 115 : #ifdef PT_HAS_TCPIP 116 2 : transports |= PT_TRANSPORT_TCP | PT_TRANSPORT_UDP; 117 : #endif 118 : 119 : #if defined(PT_HAS_APPLETALK) || defined(PT_PLATFORM_APPLETALK) 120 : transports |= PT_TRANSPORT_APPLETALK; /* ADSP | NBP */ 121 : #endif 122 : 123 2 : return transports; 124 : } 125 : 126 : /* ========================================================================== */ 127 : /* Peer Name Lookup */ 128 : /* ========================================================================== */ 129 : 130 2 : const char *PeerTalk_GetPeerName(PeerTalk_Context *ctx, uint8_t name_idx) 131 : { 132 2 : if (!pt_context_valid(ctx)) 133 1 : return NULL; 134 : 135 1 : return pt_get_peer_name(ctx, name_idx); 136 : }