Changeset 45825a3 in thomson


Ignore:
Timestamp:
Jan 29, 2013, 9:11:50 PM (11 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
f7791a2
Parents:
65a4aad
Message:

Add some safety checks

git-svn-id: svn://localhost/thomson@31 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

Location:
elec/CrO2/software
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Tape.cpp

    r65a4aad r45825a3  
    1212#include <string.h>
    1313#include <string>
     14#include <stdexcept>
    1415
    1516Tape::~Tape()
     
    2122{
    2223        std::string fnam(filename);
    23         std::string fext(fnam.substr(fnam.length() - 3));
     24        try {
     25                std::string fext(fnam.substr(fnam.length() - 3));
    2426
    25         // Load formats identified only by extension last
    26         if (fext == "TAP" || fext == "tap");
    27                 return new ZXTAP(filename);
    28         if (fext == ".K5" || fext == ".k5");
    29                 return new K5(filename);
     27                // Load formats identified only by extension last
     28                if (fext == "TAP" || fext == "tap");
     29                        return new ZXTAP(filename);
     30                if (fext == ".K5" || fext == ".k5");
     31                        return new K5(filename);
     32        } catch(std::out_of_range e) {}
    3033        throw "Unable to guess tape format";
    3134}
  • elec/CrO2/software/device_bekit.cpp

    r65a4aad r45825a3  
    1717        public:
    1818                DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product);
     19                virtual ~DeviceScanner() {}
    1920
    2021                // BUSBRoster
    21                 status_t DeviceAdded(BUSBDevice* device);
    22                 void DeviceRemoved(BUSBDevice* device);
     22                virtual status_t DeviceAdded(BUSBDevice* device);
     23                virtual void DeviceRemoved(BUSBDevice* device);
    2324
    2425                BUSBDevice* handle;
     
    3334        if (instance == NULL) {
    3435                DeviceScanner* scanner = new DeviceScanner(vid, pid, vendor, product);
     36                scanner->Start();
     37                        // Can't be done in the cosntructor, we need a fully setup vtable
    3538
    3639                while(scanner->handle == NULL); // FIXME don't hog CPU, and timeout
    3740                //throw "Device not found. Is the USB cable plugged correctly?";
    3841
     42                instance = new HaikuDevice(scanner->handle);
     43
    3944                // We have our device, don't need the roster anymore.
    40                 delete scanner;
    41 
    42                 instance = new HaikuDevice(scanner->handle);
     45                //delete scanner;
    4346        }
    4447
     
    8790
    8891DeviceScanner::DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product)
    89         : vid(vid)
     92        : handle(NULL)
     93        , vid(vid)
    9094        , pid(pid)
    9195        , vendor(vendor)
     
    128132        handle = NULL;
    129133}
    130 
  • elec/CrO2/software/gui.cpp

    r65a4aad r45825a3  
    192192                        file = Tape::load(name);
    193193                } catch (const char* error) {
     194                        // FIXME popup an error dialog
    194195                        puts(error);
    195196                        return IUP_DEFAULT;
Note: See TracChangeset for help on using the changeset viewer.