int main (int argc, char *argv[]) { char cmd[10]; int num, end = 0; int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE, usbobex = FALSE; obex_t *handle; #ifdef HAVE_BLUETOOTH bdaddr_t bdaddr; uint8_t channel = 0; #endif #ifdef HAVE_USB obex_interface_t *obex_intf; #endif struct context global_context = {0,}; #ifndef _WIN32 char *port; obex_ctrans_t custfunc; if( (argc == 2 || argc ==3) && (strcmp(argv[1], "-s") == 0 ) ) cobex = TRUE; if( (argc == 2 || argc ==3) && (strcmp(argv[1], "-r") == 0 ) ) { cobex = TRUE; r320 = TRUE; } #endif if( (argc == 2) && (strcmp(argv[1], "-i") == 0 ) ) tcpobex = TRUE; if( (argc >= 2) && (strcmp(argv[1], "-b") == 0 ) ) btobex = TRUE; if( (argc >= 2) && (strcmp(argv[1], "-u") == 0 ) ) usbobex = TRUE; if(cobex) { #ifndef _WIN32 if(argc == 3) port = argv[2]; else port = "/dev/ttyS0"; if(r320) printf("OBEX to R320 on %s!\n", port); else printf("OBEX on %s!\n", port); custfunc.customdata = cobex_open(port, r320); if(custfunc.customdata == NULL) { printf("cobex_open() failed\n"); return -1; } if(! (handle = OBEX_Init(OBEX_TRANS_CUSTOM, obex_event, 0))) { perror( "OBEX_Init failed"); return -1; } custfunc.connect = cobex_connect; custfunc.disconnect = cobex_disconnect; custfunc.write = cobex_write; custfunc.handleinput = cobex_handle_input; custfunc.listen = cobex_connect; // Listen and connect is 100% same on cable if(OBEX_RegisterCTransport(handle, &custfunc) < 0) { printf("Custom transport callback-registration failed\n"); } #else printf("Not implemented in Win32 yet.\n"); #endif // _WIN32 } else if(tcpobex) { printf("Using TCP transport\n"); if(! (handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0))) { perror( "OBEX_Init failed"); exit(0); } } else if(btobex) { #ifndef _WIN32 switch (argc) { #ifdef HAVE_BLUETOOTH case 4: str2ba(argv[2], &bdaddr); channel = atoi(argv[3]); break; case 3: str2ba(argv[2], &bdaddr); if (bacmp(&bdaddr, BDADDR_ANY) == 0) channel = atoi(argv[2]); else channel = BT_CHANNEL; break; case 2: bacpy(&bdaddr, BDADDR_ANY); channel = BT_CHANNEL; break; #endif default: printf("Wrong number of arguments\n"); exit(0); } printf("Using Bluetooth RFCOMM transport\n"); if(! (handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0))) { perror( "OBEX_Init failed"); exit(0); } #else printf("Not implemented in Win32 yet.\n"); #endif // _WIN32 } else if(usbobex) { #ifdef HAVE_USB int i, interfaces_number, intf_num; switch (argc) { case 2: printf("Using USB transport, querying available interfaces\n"); if(! (handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0))) { perror( "OBEX_Init failed"); exit(0); } interfaces_number = OBEX_FindInterfaces(handle, &obex_intf); for (i=0; i < interfaces_number; i++) printf("Interface %d: %s %s %s\n", i, obex_intf[i].usb.manufacturer, obex_intf[i].usb.product, obex_intf[i].usb.control_interface); printf("Use '%s -u interface_number' to run interactive OBEX test client\n", argv[0]); OBEX_Cleanup(handle); exit(0); break; case 3: intf_num = atoi(argv[2]); printf("Using USB transport \n"); if(! (handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0))) { perror( "OBEX_Init failed"); exit(0); } interfaces_number = OBEX_FindInterfaces(handle, &obex_intf); if (intf_num >= interfaces_number) { printf( "Invalid interface number\n"); exit(0); } obex_intf += intf_num; break; default: printf("Wrong number of arguments\n"); exit(0); } #else printf("Not compiled with USB support\n"); exit(0); #endif } else { printf("Using IrDA transport\n"); if(! (handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0))) { perror( "OBEX_Init failed"); exit(0); } } OBEX_SetUserData(handle, &global_context); printf( "OBEX Interactive test client/server.\n"); while (!end) { printf("> "); num = scanf("%s", cmd); switch (cmd[0] | 0x20) { case 'q': end=1; break; case 'g': get_client(handle, &global_context); break; case 't': setpath_client(handle); break; case 'p': put_client(handle); break; case 'x': push_client(handle); break; case 'c': /* First connect transport */ if(tcpobex) { if(TcpOBEX_TransportConnect(handle, NULL, 0) < 0) { printf("Transport connect error! (TCP)\n"); break; } } if(cobex) { if(OBEX_TransportConnect(handle, (void*) 1, 0) < 0) { printf("Transport connect error! (Serial)\n"); break; } } if(btobex) { #ifdef HAVE_BLUETOOTH if (bacmp(&bdaddr, BDADDR_ANY) == 0) { printf("Device address error! (Bluetooth)\n"); break; } if(BtOBEX_TransportConnect(handle, BDADDR_ANY, &bdaddr, channel) <0) { printf("Transport connect error! (Bluetooth)\n"); break; } #else printf("Transport not found! (Bluetooth)\n"); #endif } if (usbobex) { #ifdef HAVE_USB if (OBEX_InterfaceConnect(handle, obex_intf) < 0) { printf("Transport connect error! (USB)\n"); break; } #else printf("Transport not found! (USB)\n"); #endif } if (!tcpobex && !cobex && !btobex && !usbobex) { if(IrOBEX_TransportConnect(handle, IR_SERVICE) < 0) { printf("Transport connect error! (IrDA)\n"); break; } } // Now send OBEX-connect. connect_client(handle); break; case 'd': disconnect_client(handle); break; case 's': /* First register server */ if(tcpobex) { if(TcpOBEX_ServerRegister(handle, NULL, 0) < 0) { printf("Server register error! (TCP)\n"); break; } } if(cobex) { if(OBEX_ServerRegister(handle, (void*) 1, 0) < 0) { printf("Server register error! (Serial)\n"); break; } } if(btobex) { #ifdef HAVE_BLUETOOTH if(BtOBEX_ServerRegister(handle, BDADDR_ANY, channel) < 0) { printf("Server register error! (Bluetooth)\n"); break; } #else printf("Transport not found! (Bluetooth)\n"); #endif } if (usbobex) { printf("Transport not found! (USB)\n"); } if (!tcpobex && !cobex && !btobex && !usbobex) { if(IrOBEX_ServerRegister(handle, IR_SERVICE) < 0) { printf("Server register error! (IrDA)\n"); break; } } /* No process server events */ server_do(handle); break; default: printf("Unknown command %s\n", cmd); } } #ifndef _WIN32 if(cobex) cobex_close(custfunc.customdata); #endif return 0; }
/* * Function main (argc, ) * * Starts all the fun! * */ int main(int argc, char *argv[]) { obex_object_t *object; int ret; unsigned height,width; int i; DAParseArguments(argc, argv, options, sizeof(options)/sizeof(DAProgramOption), "CapShare Document Management Dock Applet\nBen Moore [email protected]\n", VERSION); DAInitialize(displayName, "wmcapshare", 60,60, argc, argv); DAMakePixmapFromData(lcdchars2_xpm, &char_buf, &char_mask, &height, &width); DAMakePixmapFromData(lcdnums_xpm, &num_buf, &num_mask, &height, &width); DAMakePixmapFromData(base_xpm, &pixmap, &mask, &height, &width); DAMakePixmapFromData(tstatfld_xpm, &tstatfld_buf, &tstatfld_mask, &height, &width); DAMakePixmapFromData(tstatfld_xpm, &blank_buf, &blank_mask, &height, &width); DAMakePixmapFromData(capshare_xpm, &capshare_pic, &capshare_mask, &height, &width); DAMakePixmapFromData(transfering_xpm, &transfer_pic, &transfer_mask, &height, &width); DAMakePixmapFromData(connected_xpm, &connect_pic, &connect_mask, &height, &width); DAMakePixmapFromData(disconnected_xpm, &disconnect_pic, &disconnect_mask, &height, &width); DAMakePixmapFromData( plane00_xpm, &plane_anim[0], &plane_animmask[1], &height, &width); DAMakePixmapFromData( plane01_xpm, &plane_anim[1], &plane_animmask[2], &height, &width); DAMakePixmapFromData( plane02_xpm, &plane_anim[2], &plane_animmask[3], &height, &width); DAMakePixmapFromData( plane03_xpm, &plane_anim[3], &plane_animmask[4], &height, &width); DAMakePixmapFromData( plane04_xpm, &plane_anim[4], &plane_animmask[5], &height, &width); DAMakePixmapFromData( plane05_xpm, &plane_anim[5], &plane_animmask[6], &height, &width); DAMakePixmapFromData( plane06_xpm, &plane_anim[6], &plane_animmask[6], &height, &width); DAMakePixmapFromData( plane07_xpm, &plane_anim[7], &plane_animmask[7], &height, &width); DAMakePixmapFromData( plane08_xpm, &plane_anim[8], &plane_animmask[8], &height, &width); DAMakePixmapFromData( plane09_xpm, &plane_anim[9], &plane_animmask[9], &height, &width); DAMakePixmapFromData( plane10_xpm, &plane_anim[10], &plane_animmask[10], &height, &width); DAMakePixmapFromData( plane11_xpm, &plane_anim[11], &plane_animmask[11], &height, &width); DAMakePixmapFromData( plane12_xpm, &plane_anim[12], &plane_animmask[12], &height, &width); DAMakePixmapFromData( plane13_xpm, &plane_anim[13], &plane_animmask[13], &height, &width); DAMakePixmapFromData( plane14_xpm, &plane_anim[14], &plane_animmask[14], &height, &width); DAMakePixmapFromData( plane15_xpm, &plane_anim[15], &plane_animmask[15], &height, &width); DAMakePixmapFromData( plane16_xpm, &plane_anim[16], &plane_animmask[16], &height, &width); DAMakePixmapFromData( plane17_xpm, &plane_anim[17], &plane_animmask[17], &height, &width); DAMakePixmapFromData( plane18_xpm, &plane_anim[18], &plane_animmask[18], &height, &width); DAMakePixmapFromData( plane19_xpm, &plane_anim[19], &plane_animmask[19], &height, &width); gc = DefaultGC(DADisplay, DefaultScreen(DADisplay)); /* string2pixmap("recieve", &tstatfld_buf); XCopyArea(DADisplay, plane_pic, pixmap, gc, 0, 0, 60, 29, 0, 15); XCopyArea(DADisplay, tstatfld_buf, pixmap, gc, 0, 0, 42, 8, 16, 48); DASetPixmap(pixmap); XCopyArea(DADisplay, connect_pic, pixmap, gc, 0, 0, 14, 15, 0, 45); DASetPixmap(pixmap); */ XCopyArea(DADisplay, capshare_pic, pixmap, gc, 0, 0, 60, 29, 0, 15); DAShow(); while(1) { handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0); printf("Waiting for files\n"); OBEX_ServerRegister(handle, "OBEX"); while (!finished) { updateDisplay(); OBEX_HandleInput(handle, 1); } finished = FALSE; } return 0; }