Changeset 312 in pacpusframework


Ignore:
Timestamp:
07/28/14 16:11:30 (10 years ago)
Author:
Marek Kurdej
Message:

ComponentBase: added addParameter.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/ProducerConsumerExample/ConsumerExample.cpp

    r293 r312  
    1717    LOG_TRACE("constructor(" << name << ")");
    1818
    19     addParameters()
    20         ("output-path", value<std::string>(&mOutputFileName)->default_value("consumer.txt"), "set output file path")
    21     ;
     19    addParameter("output-path", value<std::string>(&mOutputFileName)->default_value("consumer.txt"), "set output file path");
    2220}
    2321
  • trunk/examples/ProducerConsumerExample/ProducerExample.cpp

    r301 r312  
    2323    PACPUS_LOG_FUNCTION();
    2424
    25     namespace po = boost::program_options;
    26    
    27     addParameters()
    28         ("output-path", po::value<std::string>(&mOutputFileName)->default_value("producer.txt"), "set output file path")
    29     ;
     25    addParameter("output-path", value<std::string>(&mOutputFileName)->default_value("producer.txt"), "set output file path");
    3026}
    3127
  • trunk/include/Pacpus/PacpusTools/SharedMemory.h

    r300 r312  
    5757    /// Dtor of shared memory class.
    5858    virtual ~SharedMemory();
    59    
     59
    6060    /// Returns pointer to shared memory
    6161    virtual void* read();
    6262    /// Copies a chunk of shared memory to dst buffer
    6363    virtual void read(void* dst, int size);
    64    
     64
    6565    /// Use this method to write data in shared memory. Offset is given in bytes
    6666    virtual void write(void* data, int size, unsigned long offset = 0);
    67    
     67
    6868    /// Use this method to wait the incoming of new data
    6969    /// you can specify a timeout in ms to avoid infinite blocking or 0 (infinite)
    7070    /// @returns @b true if new data available before the timeout, @b false otherwise
    7171    virtual bool wait(unsigned long timeout = 0);
    72    
     72
    7373    /// Function that locks access to the shared memory
    7474    virtual void lockMemory();
    7575    /// Function that unlocks access to the shared memory
    7676    virtual void unlockMemory();
    77    
     77
    7878    /// Returns event handle on Windows and NULL on Unix.
    7979    virtual void* getEventIdentifier();
  • trunk/include/Pacpus/kernel/ComponentBase.h

    r290 r312  
    139139    /// Returns an object permitting to add component parameters.
    140140    boost::program_options::options_description_easy_init addParameters();
    141    
     141    void addParameter(const char* name, const char* description);
     142    void addParameter(const char* name, const boost::program_options::value_semantic* s);
     143    void addParameter(const char* name, const boost::program_options::value_semantic* s, const char* description);
     144
    142145protected:
    143146    typedef QMap<QString, InputSharedPointer> InputsMap;
  • trunk/src/FileLib/CMakeLists.txt

    r302 r312  
    6868    )
    6969    list(APPEND LIBS
    70         ${QT_LIBRARIES}
    71         optimized PacpusLib debug PacpusLib_d
    7270        optimized ${PROJECT_NAME} debug ${PROJECT_NAME}_d
    7371    )
  • trunk/src/FileLib/test/TestFileLib.cpp

    r303 r312  
    5353template <
    5454    typename ErrorInfo,
    55     typename E = typename ErrorInfo::error_info::value_type
     55    typename E = typename ErrorInfo::value_type
    5656>
    5757struct HasErrorInfo
  • trunk/src/PacpusLib/ComponentBase.cpp

    r292 r312  
    9191    LOG_INFO("component " << getName() << " was created");
    9292
     93    addParameter("name", value<string>(&mName)->required(), "component name");
     94    addParameter("type", value<string>(&mTypeName)->required(), "component type");
    9395    addParameters()
    94         ("name", po::value<string>(&mName)->required(), "component name")
    95         ("type", po::value<string>(&mTypeName)->required(), "component type")
    96         ("ui", po::value<bool>(&mHasGui)->default_value(false), "whether to show GUI")
    97         ("verbose", po::value<bool>(&mVerbose)->default_value(false), "set output verbose")
    98         ("verbosity-level", po::value<int>(&mVerbosityLevel)->default_value(0), "set verbosity level")
    99         ("recording", po::value<bool>(&mIsRecording)->default_value(false), "whether to record data")
     96        //("name", value<string>(&mName)->required(), "component name")
     97        //("type", value<string>(&mTypeName)->required(), "component type")
     98        ("ui", value<bool>(&mHasGui)->default_value(false), "whether to show GUI")
     99        ("verbose", value<bool>(&mVerbose)->default_value(false), "set output verbose")
     100        ("verbosity-level", value<int>(&mVerbosityLevel)->default_value(0), "set verbosity level")
     101        ("recording", value<bool>(&mIsRecording)->default_value(false), "whether to record data")
    100102    ;
    101103}
     
    283285}
    284286
     287void ComponentBase::addParameter(const char* name, const char* description)
     288{
     289    addParameters()(name, description);
     290}
     291
     292void ComponentBase::addParameter(const char* name, const po::value_semantic* s)
     293{
     294    addParameters()(name, s);
     295}
     296
     297void ComponentBase::addParameter(const char* name, const po::value_semantic* s, const char* description)
     298{
     299    addParameters()(name, s, description);
     300}
     301       
    285302class DomElementParser
    286303    : boost::noncopyable
  • trunk/src/PacpusTools/src/PosixShMem.cpp

    r162 r312  
    6666        result = true;
    6767    }
    68    
     68
    6969    /////////////////////////////////////////
    7070    if (result) {
  • trunk/src/PacpusTools/src/SharedMemory.cpp

    r303 r312  
    6262            << ". Message: " << (const char *) lpMsgBuf
    6363            << ". Program will exit"
    64             ); 
    65         ::exit(-1); 
     64            );
     65        ::exit(-1);
    6666    }
    6767
    6868    // create the event - autoreset mode
    69     event_ = CreateEvent(NULL, false, false, eventName.c_str()); 
     69    event_ = CreateEvent(NULL, false, false, eventName.c_str());
    7070
    7171    // lock the semaphore and try to create the shared memory
    72     lockMemory(); 
    73     shMemHandle_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,        PAGE_READWRITE, 0, size, name); 
     72    lockMemory();
     73    shMemHandle_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,        PAGE_READWRITE, 0, size, name);
    7474    if (shMemHandle_ == NULL) {
    7575        LOG_FATAL("cannot create shared memory segment '" << name << "'"
    7676            << ". Error: " << GetLastError()
    7777            << ". Program will exit"
    78             ); 
     78            );
    7979        ::exit(-1);
    8080    }
    8181
    8282    // Map the memory to a local pointer
    83     shMem_ = MapViewOfFile(shMemHandle_, FILE_MAP_ALL_ACCESS, 0, 0, 0); 
     83    shMem_ = MapViewOfFile(shMemHandle_, FILE_MAP_ALL_ACCESS, 0, 0, 0);
    8484    if (shMem_ == NULL) {
    8585        LOG_FATAL("cannot map the view of file of the shared memory segment '" << name << "'"
    8686            << ". Error: " << GetLastError()
    8787            << ". Program will exit"
    88             ); 
     88            );
    8989        ::exit(-1);
    9090    }
    9191
    92     LOG_INFO("created Win32 shared memory '" << name << "'"); 
     92    LOG_INFO("created Win32 shared memory '" << name << "'");
    9393
    9494    unlockMemory();
     
    135135        result = true;
    136136    }
    137    
     137
    138138    /////////////////////////////////////////
    139139    if (result) {
     
    168168    LOG_TRACE("destructor");
    169169#if PACPUS_OS_WINDOWS
    170     // free the semaphore 
    171     CloseHandle(semaphore_); 
    172     UnmapViewOfFile(shMem_); 
    173     CloseHandle(shMemHandle_); 
     170    // free the semaphore
     171    CloseHandle(semaphore_);
     172    UnmapViewOfFile(shMem_);
     173    CloseHandle(shMemHandle_);
    174174#elif PACPUS_OS_UNIX
    175175    // detach this process from the shared memory
     
    186186#if PACPUS_OS_WINDOWS
    187187    if (timeout == 0) {
    188         timeout = INFINITE; 
    189     }
    190 
    191     DWORD status = 0; 
    192     status = WaitForSingleObject(event_, timeout); 
     188        timeout = INFINITE;
     189    }
     190
     191    DWORD status = 0;
     192    status = WaitForSingleObject(event_, timeout);
    193193
    194194    if (status == WAIT_OBJECT_0) {
    195         return true; 
     195        return true;
    196196    } else {
    197         return false; 
     197        return false;
    198198    }
    199199#elif PACPUS_OS_UNIX
     
    209209    void* shMem;
    210210#if PACPUS_OS_WINDOWS
    211     lockMemory(); 
     211    lockMemory();
    212212#endif
    213213    shMem = shMem_;
    214214#if PACPUS_OS_WINDOWS
    215     unlockMemory(); 
     215    unlockMemory();
    216216#endif
    217217    return shMem;
     
    221221{
    222222    lockMemory();
    223     memcpy(dst, shMem_, size); 
     223    memcpy(dst, shMem_, size);
    224224    unlockMemory();
    225225}
     
    228228{
    229229#if PACPUS_OS_WINDOWS
    230     return event_; 
     230    return event_;
    231231#elif PACPUS_OS_UNIX
    232232    LOG_TRACE("no event identifier");
     
    241241    LOG_TRACE("writing " << size << " bytes to shared memory at offset " << offset);
    242242#if PACPUS_OS_WINDOWS
    243     lockMemory(); 
     243    lockMemory();
    244244    //unsigned long * dest = (unsigned long *)shMem_ + offset;
    245245    char * dest = (char *)shMem_ + offset;
    246     //printf("adresses : shm : %x  dest : %x   offset : %x \n",shMem_, dest, offset); 
     246    //printf("adresses : shm : %x  dest : %x   offset : %x \n",shMem_, dest, offset);
    247247    memcpy(dest, data, size);
    248248    unlockMemory();
    249     SetEvent(event_); 
     249    SetEvent(event_);
    250250#elif PACPUS_OS_UNIX
    251251    lockMemory();
     
    267267{
    268268#if PACPUS_OS_WINDOWS
    269     WaitForSingleObject(semaphore_, INFINITE); 
     269    WaitForSingleObject(semaphore_, INFINITE);
    270270#elif PACPUS_OS_UNIX
    271271    BOOST_ASSERT(memory_);
     
    279279{
    280280#if PACPUS_OS_WINDOWS
    281     ReleaseSemaphore(semaphore_, 1, NULL); 
     281    ReleaseSemaphore(semaphore_, 1, NULL);
    282282#elif PACPUS_OS_UNIX
    283283    BOOST_ASSERT(memory_);
Note: See TracChangeset for help on using the changeset viewer.