diff --git a/core/app/CMakeLists.txt b/core/app/CMakeLists.txt index dd1e19c9f0..a512f251dd 100644 --- a/core/app/CMakeLists.txt +++ b/core/app/CMakeLists.txt @@ -1,586 +1,586 @@ # # Copyright (c) 2010-2018 by Gilles Caulier, # Copyright (c) 2015 by Veaceslav Munteanu, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif (POLICY CMP0063) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/utils/digikam_version.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/utils/digikam_version.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/utils/digikam_dbconfig.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/utils/digikam_dbconfig.h) # digikam core set(DIGIKAMCORE_OBJECTS $ $ $ $ $ $ $ $ $ $ $ $ $ # widgets $ $ $ $ $ # utilities $ $ $ $ $ $ $ $ $ $ $ $ $ utils/digikam_debug.cpp ) if(Marble_FOUND) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ $ $ ) endif() if(KF5AkonadiContact_FOUND) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ ) endif() if(KF5Sane_FOUND) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ ) endif() if(FLEX_FOUND AND BISON_FOUND AND KF5ThreadWeaver_FOUND) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ ) endif() if(LibXml2_FOUND AND LibXslt_FOUND) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ ) endif() if(ENABLE_MEDIAPLAYER) set(DIGIKAMCORE_OBJECTS ${DIGIKAMCORE_OBJECTS} $ ) endif() include_directories($ $ $ $ $ $ $ $ $ $ $ $ $) if(ENABLE_QWEBENGINE) include_directories($) else() include_directories($) endif() if(KF5KIO_FOUND) include_directories($) endif() if(HAVE_OPENGL) include_directories($) endif() if(Gphoto2_FOUND) include_directories(${GPHOTO2_INCLUDE_DIRS}) endif() add_library(digikamcore SHARED ${DIGIKAMCORE_OBJECTS} ) add_dependencies(digikamcore digikam-gitversion) generate_export_header(digikamcore BASE_NAME digikam EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/utils/digikam_core_export.h") target_link_libraries(digikamcore PUBLIC Qt5::Core Qt5::Gui Qt5::Xml Qt5::XmlPatterns Qt5::Widgets Qt5::Sql Qt5::PrintSupport Qt5::Concurrent KF5::Solid KF5::WindowSystem KF5::ConfigGui KF5::CoreAddons KF5::Service KF5::XmlGui KF5::I18n # Required by CImg which use pthread internally. ${CMAKE_THREAD_LIBS_INIT} ${LCMS2_LIBRARIES} # filters ${TIFF_LIBRARIES} PNG::PNG ${JPEG_LIBRARIES} ${EXIV2_LIBRARIES} ${FFMPEG_LIBRARIES} ${OPENMP_LDFLAGS} libdng ) if(ENABLE_QWEBENGINE) target_link_libraries(digikamcore PUBLIC Qt5::WebEngineWidgets) else() target_link_libraries(digikamcore PUBLIC Qt5::WebKitWidgets) endif() if(ENABLE_DBUS) target_link_libraries(digikamcore PUBLIC Qt5::DBus) endif() if(KF5IconThemes_FOUND) target_link_libraries(digikamcore PUBLIC KF5::IconThemes) endif() if(KF5KIO_FOUND) target_link_libraries(digikamcore PUBLIC KF5::KIOCore) target_link_libraries(digikamcore PUBLIC KF5::KIOWidgets) endif() if(KF5Notifications_FOUND) target_link_libraries(digikamcore PUBLIC KF5::Notifications) endif() if(KF5NotifyConfig_FOUND) target_link_libraries(digikamcore PUBLIC KF5::NotifyConfig) endif() if(Marble_FOUND) target_link_libraries(digikamcore PUBLIC ${MARBLE_LIBRARIES}) endif() if(X11_FOUND) target_link_libraries(digikamcore PUBLIC Qt5::X11Extras ${X11_LIBRARIES}) endif() if(Jasper_FOUND) target_link_libraries(digikamcore PUBLIC ${JASPER_LIBRARIES}) endif() # LibLqr-1 library rules for content-aware filter if(Lqr-1_FOUND) target_link_libraries(digikamcore PRIVATE ${LQR-1_LIBRARIES}) endif() if(LensFun_FOUND) target_include_directories(digikamcore PUBLIC ${LENSFUN_INCLUDE_DIRS}) target_link_libraries(digikamcore PUBLIC ${LENSFUN_LIBRARIES}) endif() # for nrfilter if(OpenCV_FOUND) target_link_libraries(digikamcore PRIVATE ${OpenCV_LIBRARIES}) endif() if(KF5FileMetaData_FOUND) target_link_libraries(digikamcore PUBLIC baloowrap) endif() if(HAVE_OPENGL) target_link_libraries(digikamcore PUBLIC Qt5::OpenGL ${OPENGL_LIBRARIES} ) endif() if(KF5Sane_FOUND) target_link_libraries(digikamcore PUBLIC KF5::Sane) endif() if(KF5AkonadiContact_FOUND) target_link_libraries(digikamcore PUBLIC KF5::AkonadiContact) endif() if(KF5CalendarCore_FOUND) target_link_libraries(digikamcore PUBLIC KF5::CalendarCore) endif() if(FLEX_FOUND AND BISON_FOUND AND KF5ThreadWeaver_FOUND) target_link_libraries(digikamcore PUBLIC KF5::ThreadWeaver) endif() if(LibXml2_FOUND AND LibXslt_FOUND) target_link_libraries(digikamcore PUBLIC ${LIBXSLT_EXSLT_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXML2_LIBRARIES}) endif() if(KF5Vkontakte_FOUND) target_link_libraries(digikamcore PUBLIC KF5::Vkontakte) endif() if(APPLE) target_link_libraries(digikamcore PUBLIC /System/Library/Frameworks/AppKit.framework) endif() if(WIN32) target_link_libraries(digikamcore PUBLIC wsock32 ws2_32) endif() if(ENABLE_MEDIAPLAYER) target_link_libraries(digikamcore PUBLIC ${QTAV_LIBRARIES}) endif() set_target_properties(digikamcore PROPERTIES VERSION ${DIGIKAM_VERSION_SHORT} SOVERSION ${DIGIKAM_VERSION_SHORT}) install(TARGETS digikamcore ${INSTALL_TARGETS_DEFAULT_ARGS}) ########################## digiKam GUI sources ############################# if(ENABLE_DBUS) qt5_add_dbus_adaptor(digikamadaptor_SRCS main/org.kde.digikam.xml main/digikamapp.h Digikam::DigikamApp) endif() set(libdigikamgui_SRCS main/digikamapp.cpp main/digikamapp_solid.cpp main/digikamapp_camera.cpp main/digikamapp_import.cpp main/digikamapp_export.cpp main/digikamapp_config.cpp main/digikamapp_tools.cpp main/digikamapp_setup.cpp date/dpopupframe.cpp date/ddateedit.cpp date/ddatetable.cpp date/ddatetable_p.cpp date/ddatepicker.cpp date/ddatepicker_p.cpp date/ddatetimeedit.cpp date/ddatepickerpopup.cpp date/datefolderview.cpp date/monthwidget.cpp date/timelinewidget.cpp dragdrop/importdragdrop.cpp dragdrop/albumdragdrop.cpp dragdrop/ddragobjects.cpp dragdrop/imagedragdrop.cpp dragdrop/tagdragdrop.cpp filters/filtersidebarwidget.cpp filters/tagfilterview.cpp items/tooltipfiller.cpp items/digikamimageview.cpp items/digikamimageview_p.cpp items/digikamimagedelegate.cpp items/imagecategorizedview.cpp items/imagecategorydrawer.cpp items/imagedelegate.cpp items/imagethumbnailbar.cpp items/imagethumbnaildelegate.cpp items/imageviewutilities.cpp items/digikamimagefacedelegate.cpp items/overlays/assignnameoverlay.cpp items/overlays/facerejectionoverlay.cpp items/overlays/groupindicatoroverlay.cpp items/overlays/imagefsoverlay.cpp items/overlays/imageratingoverlay.cpp items/overlays/imagerotationoverlay.cpp items/overlays/imagecoordinatesoverlay.cpp items/overlays/imageselectionoverlay.cpp utils/contextmenuhelper.cpp utils/digikam_debug.cpp utils/componentsinfo.cpp utils/groupingviewimplementation.cpp views/tableview/tableview.cpp views/tableview/tableview_treeview.cpp views/tableview/tableview_treeview_delegate.cpp views/tableview/tableview_column_configuration_dialog.cpp views/tableview/tableview_model.cpp views/tableview/tableview_columns.cpp views/tableview/tableview_column_audiovideo.cpp views/tableview/tableview_column_file.cpp views/tableview/tableview_column_geo.cpp views/tableview/tableview_column_digikam.cpp views/tableview/tableview_column_item.cpp views/tableview/tableview_column_photo.cpp views/tableview/tableview_column_thumbnail.cpp views/tableview/tableview_columnfactory.cpp views/tableview/tableview_selection_model_syncer.cpp views/imagepreviewviewitem.cpp views/imagepreviewview.cpp views/welcomepageview.cpp views/leftsidebarwidgets.cpp views/digikamview.cpp views/trashview.cpp views/stackedview.cpp views/sidebarwidget.cpp views/digikammodelcollection.cpp views/slideshowbuilder.cpp ${digikamadaptor_SRCS} ) if(${Marble_FOUND}) set(libdigikamgui_SRCS ${libdigikamgui_SRCS} views/mapwidgetview.cpp ) endif() add_library(digikamgui_src OBJECT ${libdigikamgui_SRCS} ) ######################### digiKam GUI objects ############################ set(DIGIKAM_OBJECTS $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ) if(${Marble_FOUND}) set(DIGIKAM_OBJECTS ${DIGIKAM_OBJECTS} $ $ ) endif() #################### Digikam GUI shared Lib ################################ add_library(digikamgui SHARED ${DIGIKAM_OBJECTS} ) target_link_libraries(digikamgui PUBLIC digikamdatabase digikamcore Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Sql Qt5::PrintSupport KF5::Solid KF5::Service KF5::WindowSystem KF5::I18n ${OpenCV_LIBRARIES} ) if(ENABLE_QWEBENGINE) target_link_libraries(digikamgui PUBLIC Qt5::WebEngineWidgets) else() target_link_libraries(digikamgui PUBLIC Qt5::WebKitWidgets) endif() if(ENABLE_DBUS) target_link_libraries(digikamgui PUBLIC Qt5::DBus) endif() if(KF5IconThemes_FOUND) target_link_libraries(digikamgui PUBLIC KF5::IconThemes) endif() if(KF5KIO_FOUND) target_link_libraries(digikamgui PUBLIC KF5::KIOWidgets) endif() if(${Marble_FOUND}) target_link_libraries(digikamgui PUBLIC ${MARBLE_LIBRARIES}) endif() if(APPLE) target_link_libraries(digikamgui PRIVATE /System/Library/Frameworks/AppKit.framework) endif() if(HAVE_OPENGL) target_link_libraries(digikamgui PUBLIC Qt5::OpenGL ${OPENGL_LIBRARIES} ) endif() if(NOT WIN32) # To link under Solaris (see bug #274484) target_link_libraries(digikamgui PUBLIC ${MATH_LIBRARY}) endif() if(WIN32) set_target_properties(digikamgui PROPERTIES COMPILE_FLAGS -DJPEG_STATIC) endif() if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - target_link_libraries(digikamgui PRIVATE ${KVM_LIBRARY}) + target_link_libraries(digikamcore PRIVATE ${KVM_LIBRARY}) endif() if(Gphoto2_FOUND) # See bug #258931: libgphoto2 library must be the last arg for linker. # See bug #268267 : digiKam need to be linked to libusb to prevent crash # at gphoto2 init if opencv is linked with libdc1394. Libusb linking rules are # add to gphoto2 linking rules by Gphoto2 cmake detection script. target_link_libraries(digikamgui PUBLIC ${GPHOTO2_LIBRARIES}) endif() set_target_properties(digikamgui PROPERTIES VERSION ${DIGIKAM_VERSION_SHORT} SOVERSION ${DIGIKAM_VERSION_SHORT}) install(TARGETS digikamgui ${INSTALL_TARGETS_DEFAULT_ARGS}) #################### digiKam Executable #################################### set(digikam_SRCS main/main.cpp ) # this is only required by Win & OSX file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/apps/*-apps-digikam.png") ecm_add_app_icon(digikam_SRCS ICONS ${ICONS_SRCS}) add_executable(digikam ${digikam_SRCS}) add_dependencies(digikam digikam-gitversion) # To fill plist XML file for OSX ############ set(MACOSX_APP_NAME_STRING "digikam") set(MACOSX_APP_DESCRIPTION "Advanced digital photo management application") set(MACOSX_BUNDLE_LONG_VERSION_STRING ${DIGIKAM_VERSION_STRING}) set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${DIGIKAM_VERSION_SHORT}) set(MACOSX_BUNDLE_BUNDLE_VERSION ${DIGIKAM_VERSION_STRING}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/templates/Info.plist.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) set_target_properties(digikam PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) target_link_libraries(digikam PUBLIC digikamcore digikamgui libdng Qt5::Core Qt5::Gui Qt5::Widgets KF5::WindowSystem KF5::I18n ) if(ENABLE_DBUS) target_link_libraries(digikam PUBLIC Qt5::DBus) endif() if(KF5IconThemes_FOUND) target_link_libraries(digikam PUBLIC KF5::IconThemes) endif() if(KF5KIO_FOUND) target_link_libraries(digikam PUBLIC KF5::KIOWidgets) endif() install(TARGETS digikam ${INSTALL_TARGETS_DEFAULT_ARGS}) # Others Files to install ####################################################### install(PROGRAMS main/org.kde.digikam.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES main/org.kde.digikam.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES main/digikamui5.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/digikam) install(FILES main/digikam.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR}) diff --git a/core/libs/kmemoryinfo/libstatgrab/kmemoryinfo_backend.cpp b/core/libs/kmemoryinfo/libstatgrab/kmemoryinfo_backend.cpp index aef27cabbb..2dc52005b5 100644 --- a/core/libs/kmemoryinfo/libstatgrab/kmemoryinfo_backend.cpp +++ b/core/libs/kmemoryinfo/libstatgrab/kmemoryinfo_backend.cpp @@ -1,800 +1,800 @@ /* * Copyright 2010 Pino Toscano * Copyright 2011 Marcel Wiesweg * * Based on i-scream libstatgrab implementation. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License (LGPL) as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * $Id: memory_stats.c,v 1.36 2010/02/21 10:04:26 tdb Exp $ */ //krazy:skip /** Value returned : -1 : unsupported platform * 0 : parse failure from supported platform * 1 : parse done with success from supported platform */ static int get_mem_stats(Digikam::KMemoryInfo::KMemoryInfoData* const data); static int get_swap_stats(Digikam::KMemoryInfo::KMemoryInfoData* const data); static int fillMemoryInfo(Digikam::KMemoryInfo::KMemoryInfoData* const data) { int ret = get_mem_stats(data); if (ret < 1) { data->valid = ret; return ret; } ret = get_swap_stats(data); if (ret < 1) { data->valid = ret; return ret; } data->valid = 1; return 1; } #ifdef Q_OS_SOLARIS #include #include #endif #if defined(Q_OS_LINUX)// || defined(Q_OS_CYGWIN) #include #include #endif #if defined(Q_OS_FREEBSD) #include #include #include #include #include #include #endif #if defined(Q_OS_NETBSD) #include #include #include #endif #if defined(Q_OS_OPENBSD) #include #include #include #include #endif #ifdef Q_OS_HPUX #include #include #include #endif #ifdef Q_OS_WIN #include #endif #if defined(Q_OS_LINUX) char* sg_f_read_line(FILE* f, const char* string) { /* Max line length. 8k should be more than enough */ static char line[8192]; while((fgets(line, sizeof(line), f))!=NULL) { if (strncmp(string, line, strlen(string))==0) { return line; } } //sg_set_error(SG_ERROR_PARSE, NULL); return NULL; } #endif // defined(Q_OS_LINUX) #if (defined(Q_OS_FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD) kvm_t* sg_get_kvm() { static kvm_t* kvmd = NULL; if (kvmd != NULL) { return kvmd; } - kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL); + kvmd = kvm_openfiles(NULL, "/dev/null", NULL, O_RDONLY, NULL); if (kvmd == NULL) { //sg_set_error(SG_ERROR_KVM_OPENFILES, NULL); } return kvmd; } /* Can't think of a better name for this function */ kvm_t* sg_get_kvm2() { static kvm_t* kvmd2 = NULL; if (kvmd2 != NULL) { return kvmd2; } kvmd2 = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); if (kvmd2 == NULL) { //sg_set_error(SG_ERROR_KVM_OPENFILES, NULL); } return kvmd2; } #endif // (defined(Q_OS_FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD) #if defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) struct uvmexp* sg_get_uvmexp() { int mib[2]; size_t size = sizeof(struct uvmexp); static struct uvmexp uvm; // struct uvmexp* new; mib[0] = CTL_VM; mib[1] = VM_UVMEXP; if (sysctl(mib, 2, &uvm, &size, NULL, 0) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_VM.VM_UVMEXP"); return NULL; } return &uvm; } #endif // defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) #ifdef Q_OS_HPUX struct pst_KMemoryInfo::static* sg_get_pstat_static() { static int got = 0; static struct pst_static pst; if (!got) { if (pstat_getstatic(&pst, sizeof pst, 1, 0) == -1) { //sg_set_error_with_errno(SG_ERROR_PSTAT, "pstat_static"); return NULL; } got = 1; } return &pst; } #endif // Q_OS_HPUX // ---------------------------------------------------------------------------- int get_mem_stats(Digikam::KMemoryInfo::KMemoryInfoData* const data) { #ifdef Q_OS_HPUX struct pst_static* pstat_static = 0; struct pst_dynamic pstat_dynamic; long long pagesize; #endif // Q_OS_HPUX #ifdef Q_OS_SOLARIS kstat_ctl_t* kc = 0; kstat_t* ksp = 0; kstat_named_t* kn = 0; long totalmem; int pagesize; #endif // Q_OS_SOLARIS #if defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) char* line_ptr = 0; unsigned long long value; FILE* f = 0; #endif // defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) #if defined(Q_OS_FREEBSD) || defined(Q_OS_DFBSD) int mib[2]; u_long physmem; size_t size; - u_long free_count; - u_long cache_count; - u_long inactive_count; + u_int free_count; + u_int cache_count; + u_int inactive_count; int pagesize; #endif // defined(Q_OS_FREEBSD) || defined(Q_OS_DFBSD) #if defined(Q_OS_NETBSD) struct uvmexp* uvm = 0; #endif // defined(Q_OS_NETBSD) #if defined(Q_OS_OPENBSD) int mib[2]; struct vmtotal vmtotal; size_t size; int pagesize, page_multiplier; #endif // defined(Q_OS_OPENBSD) #ifdef Q_OS_WIN MEMORYSTATUSEX memstats; #endif #ifdef Q_OS_OSX Q_UNUSED(data); #endif #ifdef Q_OS_HPUX data->platform = QLatin1String("HPUX"); if((pagesize = sysconf(_SC_PAGESIZE)) == -1) { //sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PAGESIZE"); return 0; } if (pstat_getdynamic(&pstat_dynamic, sizeof(pstat_dynamic), 1, 0) == -1) { //sg_set_error_with_errno(SG_ERROR_PSTAT, "pstat_dynamic"); return 0; } pstat_static = sg_get_pstat_static(); if (pstat_static == NULL) { return 0; } /* FIXME Does this include swap? */ data->totalRam = ((long long) pstat_static->physical_memory) * pagesize; data->freeRam = ((long long) pstat_dynamic.psd_free) * pagesize; data->usedRam = data->totalRam - data->freeRam; return 1; #endif // Q_OS_HPUX #ifdef Q_OS_SOLARIS data->platform = QLatin1String("SOLARIS"); if((pagesize = sysconf(_SC_PAGESIZE)) == -1) { //sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PAGESIZE"); return 0; } if((totalmem = sysconf(_SC_PHYS_PAGES)) == -1) { //sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PHYS_PAGES"); return 0; } if ((kc = kstat_open()) == NULL) { //sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); return 0; } if((ksp = kstat_lookup(kc, "unix", 0, "system_pages")) == NULL) { //sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,0,system_pages"); return 0; } if (kstat_read(kc, ksp, 0) == -1) { //sg_set_error(SG_ERROR_KSTAT_READ, NULL); return 0; } if((kn = (kstat_named_t*)kstat_data_lookup(ksp, "freemem")) == NULL) { //sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "freemem"); return 0; } kstat_close(kc); data->totalRam = (long long)totalmem * (long long)pagesize; data->freeRam = ((long long)kn->value.ul) * (long long)pagesize; data->usedRam = data->totalRam - data->freeRam; return 1; #endif // Q_OS_SOLARIS #if defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) data->platform = QLatin1String("LINUX"); if ((f = fopen("/proc/meminfo", "r")) == NULL) { //sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/meminfo"); return 0; } while ((line_ptr = sg_f_read_line(f, "")) != NULL) { if (sscanf(line_ptr, "%*s %llu kB", &value) != 1) { continue; } value *= 1024; if (strncmp(line_ptr, "MemTotal:", 9) == 0) { data->totalRam = value; } else if (strncmp(line_ptr, "MemFree:", 8) == 0) { data->freeRam = value; } else if (strncmp(line_ptr, "Cached:", 7) == 0) { data->cacheRam = value; } } fclose(f); data->usedRam = data->totalRam - data->freeRam; return 1; #endif // defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) #if defined(Q_OS_FREEBSD) data->platform = QLatin1String("FREEBSD"); /* Returns bytes */ mib[0] = CTL_HW; mib[1] = HW_PHYSMEM; size = sizeof physmem; if (sysctl(mib, 2, &physmem, &size, NULL, 0) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_HW.HW_PHYSMEM"); return 0; } data->totalRam = physmem; /*returns pages*/ size = sizeof free_count; if (sysctlbyname("vm.stats.vm.v_free_count", &free_count, &size, NULL, 0) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "vm.stats.vm.v_free_count"); return 0; } size = sizeof inactive_count; if (sysctlbyname("vm.stats.vm.v_inactive_count", &inactive_count , &size, NULL, 0) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "vm.stats.vm.v_inactive_count"); return 0; } size = sizeof cache_count; if (sysctlbyname("vm.stats.vm.v_cache_count", &cache_count, &size, NULL, 0) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "vm.stats.vm.v_cache_count"); return 0; } /* Because all the vm.stats returns pages, I need to get the page size. * After that I then need to multiple the anything that used vm.stats to * get the system statistics by pagesize */ pagesize = getpagesize(); data->cacheRam = cache_count * pagesize; /* Of couse nothing is ever that simple :) And I have inactive pages to * deal with too. So I'm going to add them to free memory :) */ data->freeRam = (free_count*pagesize)+(inactive_count*pagesize); data->usedRam = physmem-data->freeRam; return 1; #endif // defined(Q_OS_FREEBSD) #if defined(Q_OS_NETBSD) data->platform = QLatin1String("NETBSD"); if ((uvm = sg_get_uvmexp()) == NULL) { return 0; } data->totalRam = uvm->pagesize * uvm->npages; data->cacheRam = uvm->pagesize * (uvm->filepages + uvm->execpages); data->freeRam = uvm->pagesize * (uvm->free + uvm->inactive); data->usedRam = data->totalRam - data->freeRam; return 1; #endif // defined(Q_OS_NETBSD) #if defined(Q_OS_OPENBSD) data->platform = QLatin1String("OPENBSD"); /* The code in this section is based on the code in the OpenBSD * top utility, located at src/usr.bin/top/machine.c in the * OpenBSD source tree. * * For fun, and like OpenBSD top, we will do the multiplication * converting the memory stats in pages to bytes in base 2. */ /* All memory stats in OpenBSD are returned as the number of pages. * To convert this into the number of bytes we need to know the * page size on this system. */ pagesize = sysconf(_SC_PAGESIZE); /* The pagesize gives us the base 10 multiplier, so we need to work * out what the base 2 multiplier is. This means dividing * pagesize by 2 until we reach unity, and counting the number of * divisions required. */ page_multiplier = 0; while (pagesize > 1) { page_multiplier++; pagesize >>= 1; } /* We can now ret the raw VM stats (in pages) using the * sysctl interface. */ mib[0] = CTL_VM; mib[1] = VM_METER; size = sizeof(vmtotal); if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) { bzero(&vmtotal, sizeof(vmtotal)); //sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_VM.VM_METER"); return 0; } /* Convert the raw stats to bytes, and return these to the caller */ data->usedRam = (vmtotal.t_rm << page_multiplier); /* total real mem in use */ data->cacheRam = 0; /* no cache stats */ data->freeRam = (vmtotal.t_free << page_multiplier); /* free memory pages */ data->totalRam = (data->usedRam + data->freeRam); return 1; #endif // defined(Q_OS_OPENBSD) #ifdef Q_OS_WIN data->platform = QLatin1String("WINDOWS"); memstats.dwLength = sizeof(memstats); if (!GlobalMemoryStatusEx(&memstats)) { //sg_set_error_with_errno(SG_ERROR_MEMSTATUS, NULL); return 0; } data->freeRam = memstats.ullAvailPhys; data->totalRam = memstats.ullTotalPhys; data->usedRam = data->totalRam - data->freeRam; //if(read_counter_large(SG_WIN32_MEM_CACHE, &data->cacheRam)) { data->cacheRam = 0; //} return 1; #endif // Q_OS_WIN return -1; } // ---------------------------------------------------------------------------- #ifdef Q_OS_SOLARIS #ifdef _FILE_OFFSET_BITS #undef _FILE_OFFSET_BITS #endif #include #include #include #endif #if defined(Q_OS_LINUX) //|| defined(Q_OS_CYGWIN) #include #include #endif #if defined(Q_OS_FREEBSD) #ifdef Q_OS_FREEBSD5 #include #include #include #else #include #include #endif #include #endif #if defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) #include #include #include #include #endif #ifdef Q_OS_HPUX #include #include #include #define SWAP_BATCH 5 #endif #ifdef Q_OS_WIN #include #endif int get_swap_stats(Digikam::KMemoryInfo::KMemoryInfoData* const data) { #ifdef Q_OS_OSX Q_UNUSED(data); #endif #ifdef Q_OS_HPUX struct pst_swapinfo pstat_swapinfo[SWAP_BATCH]; int swapidx = 0; int num, i; #endif // Q_OS_HPUX #ifdef Q_OS_SOLARIS struct anoninfo ai; int pagesize; #endif // Q_OS_SOLARIS #if defined(Q_OS_LINUX) //|| defined(Q_OS_CYGWIN) FILE* f = 0; char* line_ptr = 0; unsigned long long value; #endif // defined(Q_OS_LINUX) #if defined(Q_OS_FREEBSD) int pagesize; #ifdef Q_OS_FREEBSD5 struct xswdev xsw; int mib[16], n; size_t mibsize, size; #else struct kvm_swap swapinfo; kvm_t* kvmd = 0; #endif // Q_OS_FREEBSD5 #endif // defined(Q_OS_FREEBSD) #if defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) struct uvmexp* uvm = 0; #endif // defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) #ifdef Q_OS_WIN MEMORYSTATUSEX memstats; #endif // Q_OS_WIN #ifdef Q_OS_HPUX data->totalSwap = 0; data->usedSwap = 0; data->freeSwap = 0; while (1) { num = pstat_getswap(pstat_swapinfo, sizeof pstat_swapinfo[0], SWAP_BATCH, swapidx); if (num == -1) { //sg_set_error_with_errno(SG_ERROR_PSTAT,"pstat_getswap"); return 0; } else if (num == 0) { break; } for (i = 0; i < num; i++) { struct pst_swapinfo* si = &pstat_swapinfo[i]; if ((si->pss_flags & SW_ENABLED) != SW_ENABLED) { continue; } if ((si->pss_flags & SW_BLOCK) == SW_BLOCK) { data->totalSwap += ((long long) si->pss_nblksavail) * 1024LL; data->usedSwap += ((long long) si->pss_nfpgs) * 1024LL; data->freeSwap = data->totalSwap - data->usedSwap; } if ((si->pss_flags & SW_FS) == SW_FS) { data->totalSwap += ((long long) si->pss_limit) * 1024LL; data->usedSwap += ((long long) si->pss_allocated) * 1024LL; data->freeSwap = data->totalSwap - data->usedSwap; } } swapidx = pstat_swapinfo[num - 1].pss_idx + 1; } return 1; #endif // Q_OS_HPUX #ifdef Q_OS_SOLARIS if((pagesize=sysconf(_SC_PAGESIZE)) == -1) { //sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PAGESIZE"); return 0; } if (swapctl(SC_AINFO, &ai) == -1) { //sg_set_error_with_errno(SG_ERROR_SWAPCTL, NULL); return 0; } data->totalSwap = (long long)ai.ani_max * (long long)pagesize; data->usedSwap = (long long)ai.ani_resv * (long long)pagesize; data->freeSwap = data->totalSwap - data->usedSwap; return 1; #endif // Q_OS_SOLARIS #if defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) if ((f = fopen("/proc/meminfo", "r")) == NULL) { //sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/meminfo"); return 0; } while ((line_ptr = sg_f_read_line(f, "")) != NULL) { if (sscanf(line_ptr, "%*s %llu kB", &value) != 1) { continue; } value *= 1024; if (strncmp(line_ptr, "SwapTotal:", 10) == 0) { data->totalSwap = value; } else if (strncmp(line_ptr, "SwapFree:", 9) == 0) { data->freeSwap = value; } } fclose(f); data->usedSwap = data->totalSwap - data->freeSwap; return 1; #endif // defined(Q_OS_LINUX) || defined(Q_OS_CYGWIN) #if defined(Q_OS_FREEBSD) || defined(Q_OS_DFBSD) pagesize = getpagesize(); #ifdef Q_OS_FREEBSD5 data->totalSwap = 0; data->usedSwap = 0; mibsize = sizeof mib / sizeof mib[0]; if (sysctlnametomib("vm.swap_info", mib, &mibsize) < 0) { //sg_set_error_with_errno(SG_ERROR_SYSCTLNAMETOMIB, "vm.swap_info"); return 0; } for (n = 0; ; ++n) { mib[mibsize] = n; size = sizeof xsw; if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) < 0) { break; } if (xsw.xsw_version != XSWDEV_VERSION) { //sg_set_error(SG_ERROR_XSW_VER_MISMATCH, NULL); return 0; } data->totalSwap += (long long) xsw.xsw_nblks; data->usedSwap += (long long) xsw.xsw_used; } if (errno != ENOENT) { //sg_set_error_with_errno(SG_ERROR_SYSCTL, "vm.swap_info"); return 0; } #else // Q_OS_FREEBSD5 if((kvmd = sg_get_kvm()) == NULL) { return 0; } if ((kvm_getswapinfo(kvmd, &swapinfo, 1,0)) == -1) { //sg_set_error(SG_ERROR_KVM_GETSWAPINFO, NULL); return 0; } data->totalSwap = (long long)swapinfo.ksw_total; data->usedSwap = (long long)swapinfo.ksw_used; #endif // Q_OS_FREEBSD5 data->totalSwap *= pagesize; data->usedSwap *= pagesize; data->freeSwap = data->totalSwap - data->usedSwap; return 1; #endif // defined(Q_OS_FREEBSD) || defined(Q_OS_DFBSD) #if defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) if ((uvm = sg_get_uvmexp()) == NULL) { return 0; } data->totalSwap = (long long)uvm->pagesize * (long long)uvm->swpages; data->usedSwap = (long long)uvm->pagesize * (long long)uvm->swpginuse; data->freeSwap = data->totalSwap - data->usedSwap; return 1; #endif // defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) #ifdef Q_OS_WIN memstats.dwLength = sizeof(memstats); if (!GlobalMemoryStatusEx(&memstats)) { //sg_set_error_with_errno(SG_ERROR_MEMSTATUS, "GloblaMemoryStatusEx"); return 0; } /* the PageFile stats include Phys memory "minus an overhead". * Due to this unknown "overhead" there's no way to extract just page * file use from these numbers */ data->totalSwap = memstats.ullTotalPageFile; data->freeSwap = memstats.ullAvailPageFile; data->usedSwap = data->totalSwap - data->freeSwap; return 1; #endif return -1; }