diff --git a/cmake/Conky.cmake b/cmake/Conky.cmake index 366a99e3..8d66f70d 100644 --- a/cmake/Conky.cmake +++ b/cmake/Conky.cmake @@ -47,11 +47,15 @@ if(CMAKE_SYSTEM_NAME MATCHES "NetBSD") set(OS_NETBSD true) endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD") +if(CMAKE_SYSTEM_NAME MATCHES "Haiku") + set(OS_HAIKU true) +endif(CMAKE_SYSTEM_NAME MATCHES "Haiku") + if(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY - AND NOT OS_SOLARIS) + AND NOT OS_SOLARIS AND NOT OS_HAIKU) message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.") endif(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY - AND NOT OS_SOLARIS) + AND NOT OS_SOLARIS AND NOT OS_HAIKU) include(FindThreads) find_package(Threads) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 6a688523..c5b39b2f 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -30,6 +30,8 @@ check_include_files(sys/statfs.h HAVE_SYS_STATFS_H) check_include_files(sys/param.h HAVE_SYS_PARAM_H) check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H) check_include_files(dirent.h HAVE_DIRENT_H) +check_include_files("soundcard.h;sys/soundcard.h;linux/soundcard.h" HAVE_SOME_SOUNDCARD_H) +check_include_files("linux/soundcard.h" HAVE_LINUX_SOUNDCARD_H) # Check for some functions check_function_exists(strndup HAVE_STRNDUP) @@ -75,11 +77,16 @@ if(CMAKE_SYSTEM_NAME MATCHES "NetBSD") set(OS_NETBSD true) endif(CMAKE_SYSTEM_NAME MATCHES "NetBSD") +if(CMAKE_SYSTEM_NAME MATCHES "Haiku") + set(OS_HAIKU true) + set(conky_libs ${conky_libs} -lnetwork -lintl) +endif(CMAKE_SYSTEM_NAME MATCHES "Haiku") + if(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY - AND NOT OS_SOLARIS) + AND NOT OS_SOLARIS AND NOT OS_HAIKU) message(FATAL_ERROR "Your platform, '${CMAKE_SYSTEM_NAME}', is not currently supported. Patches are welcome.") endif(NOT OS_LINUX AND NOT OS_FREEBSD AND NOT OS_OPENBSD AND NOT OS_DRAGONFLY - AND NOT OS_SOLARIS) + AND NOT OS_SOLARIS AND NOT OS_HAIKU) if(BUILD_I18N AND OS_DRAGONFLY) set(conky_libs ${conky_libs} -lintl) diff --git a/cmake/config.h.in b/cmake/config.h.in index 0b4a5683..094fe792 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -29,6 +29,9 @@ #cmakedefine HAVE_SYS_INOTIFY_H 1 #cmakedefine HAVE_DIRENT_H 1 +#cmakedefine HAVE_SOME_SOUNDCARD_H 1 +#cmakedefine HAVE_LINUX_SOUNDCARD_H 1 + #cmakedefine HAVE_STRNDUP 1 #cmakedefine HAVE_FOPENCOOKIE 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aacb5140..b83c851e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,7 +38,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h) endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h) set(conky_sources c++wrap.cc colours.cc combine.cc common.cc conky.cc core.cc - diskio.cc entropy.cc exec.cc fs.cc mail.cc mixer.cc net_stat.cc template.cc + diskio.cc entropy.cc exec.cc fs.cc mail.cc net_stat.cc template.cc mboxscan.cc read_tcpip.cc scroll.cc specials.cc tailhead.cc temphelper.cc text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc user.cc luamm.cc data-source.cc lua-config.cc setting.cc llua.cc update-cb.cc) @@ -75,8 +75,17 @@ if(OS_NETBSD) set(optional_sources ${optional_sources} ${netbsd}) endif(OS_NETBSD) +if(OS_HAIKU) + set(haiku haiku.cc) + set(optional_sources ${optional_sources} ${haiku}) +endif(OS_HAIKU) # Optional sources +if(HAVE_SOME_SOUNDCARD_H) + set(mixer mixer.cc) + set(optional_sources ${optional_sources} ${mixer}) +endif(HAVE_SOME_SOUNDCARD_H) + if(BUILD_AUDACIOUS) set(audacious audacious.cc) set(optional_sources ${optional_sources} ${audacious}) diff --git a/src/conky.cc b/src/conky.cc index 7163d776..48256ecc 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -317,6 +317,9 @@ static void print_version(void) #ifdef BUILD_IMLIB2 << _(" * Imlib2\n") #endif /* BUILD_IMLIB2 */ +#ifdef HAVE_SOME_SOUNDCARD_H + << _(" * OSS mixer support\n") +#endif /* HAVE_SOME_SOUNDCARD_H */ #ifdef BUILD_MIXER_ALSA << _(" * ALSA mixer support\n") #endif /* BUILD_MIXER_ALSA */ diff --git a/src/core.cc b/src/core.cc index f4d20f86..17f9c94f 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1058,6 +1058,7 @@ struct text_object *construct_text_object(char *s, const char *arg, free_and_zero(buf); obj->callbacks.graphval = &mem_barval; #endif /* BUILD_X11*/ +#ifdef HAVE_SOME_SOUNDCARD_H END OBJ(mixer, 0) parse_mixer_arg(obj, arg); obj->callbacks.percentage = &mixer_percentage; @@ -1079,6 +1080,7 @@ struct text_object *construct_text_object(char *s, const char *arg, END OBJ_IF(if_mixer_mute, 0) parse_mixer_arg(obj, arg); obj->callbacks.iftest = &check_mixer_muted; +#endif #ifdef BUILD_X11 END OBJ(monitor, 0) obj->callbacks.print = &print_monitor; diff --git a/src/entropy.cc b/src/entropy.cc index c18a9334..c1726169 100644 --- a/src/entropy.cc +++ b/src/entropy.cc @@ -43,6 +43,8 @@ #include "openbsd.h" #elif defined(__sun) #include "solaris.h" +#elif defined(__HAIKU__) +#include "haiku.h" #endif struct _entropy { diff --git a/src/fs.cc b/src/fs.cc index 73cf8d7c..1e317764 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -52,12 +52,14 @@ #include "freebsd.h" #elif defined(__DragonFly__) #include "dragonfly.h" +#elif defined(__HAIKU__) +#include "haiku.h" #endif #if !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && \ !defined (__OpenBSD__) && !defined(__FreeBSD__) && \ - !defined(__DragonFly__) && !defined(__sun) + !defined(__DragonFly__) && !defined(__sun) && !defined(__HAIKU__) #include #endif @@ -154,7 +156,7 @@ void get_fs_type(const char *path, char *result) { #if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || \ - defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) + defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__HAIKU__) struct statfs64 s; if (statfs64(path, &s) == 0) { diff --git a/src/haiku.cc b/src/haiku.cc new file mode 100644 index 00000000..df71ba91 --- /dev/null +++ b/src/haiku.cc @@ -0,0 +1,286 @@ +/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=cpp + * + * Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen + * Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include + +#include "haiku.h" +#include "conky.h" +#include "net_stat.h" +#include "top.h" + +static short cpu_setup = 0; + +void prepare_update() +{ +} + +int update_uptime() +{ + info.uptime = (double)system_time() / 1000000.0; + return 0; +} + +int check_mount(struct text_object *obj) +{ + /* stub */ + (void)obj; + return 0; +} + +int update_meminfo() +{ + system_info si; + + if (get_system_info(&si) != B_OK) { + fprintf(stderr, "Cannot get_system_info\n"); + return 1; + } + + info.memmax = si.max_pages * (B_PAGE_SIZE >> 10); + info.mem = si.used_pages * (B_PAGE_SIZE >> 10); + // TODO: we have some more info... + info.memwithbuffers = info.mem; + info.memeasyfree = info.memfree = info.memmax - info.mem; + + info.swapmax = si.max_swap_pages * (B_PAGE_SIZE >> 10); + info.swapfree = si.free_swap_pages * (B_PAGE_SIZE >> 10); + info.swap = (info.swapmax - info.swapfree); + + return 0; +} + +int update_net_stats() +{ + // TODO + return 1; +} + +int update_total_processes() +{ + // TODO + return 1; +} + +int update_running_processes() +{ + // TODO + return 1; +} + +void get_cpu_count(void) +{ + system_info si; + + if (get_system_info(&si) != B_OK) { + fprintf(stderr, "Cannot get_system_info\n"); + info.cpu_count = 0; + return; + } + info.cpu_count = si.cpu_count; + + info.cpu_usage = (float *) malloc((info.cpu_count + 1) * sizeof(float)); + if (info.cpu_usage == NULL) { + CRIT_ERR(NULL, NULL, "malloc"); + } +} + +int update_cpu_usage() +{ + // TODO + static bigtime_t prev = 0; + static cpu_info *prev_cpuinfo = NULL; + bigtime_t now; + cpu_info *cpuinfo; + + /* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */ + if ((cpu_setup == 0) || (!info.cpu_usage)) { + get_cpu_count(); + cpu_setup = 1; + } + + int malloc_cpu_size = sizeof(cpu_info) * (info.cpu_count + 1); + + if (!prev_cpuinfo) { + prev_cpuinfo = (cpu_info *)malloc(malloc_cpu_size); + if (prev_cpuinfo == NULL) { + CRIT_ERR(NULL, NULL, "malloc"); + } + memset(prev_cpuinfo, 0, malloc_cpu_size); + } + + cpuinfo = (cpu_info *)malloc(malloc_cpu_size); + memset(cpuinfo, 0, malloc_cpu_size); + + if (cpuinfo == NULL) { + CRIT_ERR(NULL, NULL, "malloc"); + } + + now = system_time(); + if (get_cpu_info(0, info.cpu_count, &cpuinfo[1]) == B_OK) { + for (int i = 1; i <= info.cpu_count; i++) + cpuinfo[0].active_time += cpuinfo[i].active_time; + cpuinfo[0].active_time /= info.cpu_count; + for (int i = 0; i <= info.cpu_count; i++) { + double period = (double)(now - prev); + info.cpu_usage[i] = ((double) + (cpuinfo[i].active_time - prev_cpuinfo[i].active_time)) / + period; + } + } + + memcpy(prev_cpuinfo, cpuinfo, malloc_cpu_size); + prev = now; + free(cpuinfo); + return 1; +} + +int update_load_average() +{ + // TODO + return 1; +} + +double get_acpi_temperature(int fd) +{ + return -1; +} + +void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) +{ + // TODO +} + +int get_battery_perct(const char *bat) +{ + /* + int batcapacity; + + get_battery_stats(NULL, &batcapacity, NULL, NULL); + return batcapacity; + */ + // TODO + return 0; +} + +double get_battery_perct_bar(struct text_object *obj) +{ + int batperct = get_battery_perct(obj->data.s); + return batperct; +} + +int open_acpi_temperature(const char *name) +{ + return -1; +} + +void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, const char *adapter) +{ + (void) adapter; // only linux uses this + + if (!p_client_buffer || client_buffer_size <= 0) { + return; + } + + /* not implemented */ + memset(p_client_buffer, 0, client_buffer_size); +} + +/* char *get_acpi_fan() */ +void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size) +{ + if (!p_client_buffer || client_buffer_size <= 0) { + return; + } + + /* not implemented */ + memset(p_client_buffer, 0, client_buffer_size); +} + +/* void */ +char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, + int divisor, unsigned int cpu) +{ + int freq; + char *freq_sysctl; + + if (!p_client_buffer || client_buffer_size <= 0 || !p_format + || divisor <= 0) { + return 0; + } + return 0; + // TODO +// return 1; +} + +int update_diskio(void) +{ + return 1; +} + +void get_top_info(void) +{ + int32 tmcookie = 0; + team_info tm; + struct process *proc; + + while (get_next_team_info(&tmcookie, &tm) == B_NO_ERROR) { + team_usage_info ti; + + if (get_team_usage_info(tm.team, B_TEAM_USAGE_SELF, &ti) != B_OK) + continue; + + proc = get_process(tm.team); + + proc->time_stamp = g_time; + proc->name = strndup(tm.args, sizeof(tm.args)); + proc->basename = strndup(tm.args, sizeof(tm.args)); + //proc->amount = 100.0 * p[i].ki_pctcpu / FSCALE; + proc->vsize = 0; + proc->rss = 0; + /* bigtime_t is in microseconds, total_cpu_time in centiseconds. + * Therefore we divide by 10000. */ + proc->total_cpu_time = (ti.user_time + ti.kernel_time) / 10000; + } +} + +void get_battery_short_status(char *buffer, unsigned int n, const char *bat) +{ + // TODO +} + +int get_entropy_avail(unsigned int *val) +{ + return 1; +} + +int get_entropy_poolsize(unsigned int *val) +{ + return 1; +} diff --git a/src/haiku.h b/src/haiku.h new file mode 100644 index 00000000..ec245b79 --- /dev/null +++ b/src/haiku.h @@ -0,0 +1,44 @@ +/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */ + +#ifndef HAIKU_H_ +#define HAIKU_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include "conky.h" +#include "common.h" + +int get_entropy_avail(unsigned int *); +int get_entropy_poolsize(unsigned int *); + + +/* let's just mimic statfs64 */ + +struct statfs : public fs_info {}; + +inline int statfs(const char *path, struct statfs *buf) +{ + return fs_stat_dev(dev_for_path(path), buf); +} + +#define f_blocks total_blocks +#define f_bsize block_size +#define f_bavail free_blocks +#define f_bfree free_blocks +#define f_fstypename fsh_name + + +#endif /*HAIKU_H_*/ diff --git a/src/libmpdclient.cc b/src/libmpdclient.cc index e382fe8c..8b26a105 100644 --- a/src/libmpdclient.cc +++ b/src/libmpdclient.cc @@ -56,6 +56,10 @@ # include #endif +#ifndef SUN_LEN +#define SUN_LEN(a) sizeof(a) +#endif + /* (bits + 1) / 3 (plus the sign character) */ #define INTLEN ((sizeof(int) * CHAR_BIT + 1) / 3 + 1) #define LONGLONGLEN ((sizeof(long long) * CHAR_BIT + 1) / 3 + 1) diff --git a/src/net_stat.cc b/src/net_stat.cc index 185ccaa1..366a9c35 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -43,6 +43,10 @@ #if defined(__sun) #include #endif +#if defined(__HAIKU__) +#include +#define IFF_RUNNING IFF_LINK +#endif /* network interface stuff */ @@ -510,8 +514,10 @@ int interface_up(struct text_object *obj) if (if_up_strictness.get(*state) == IFUP_UP) goto END_TRUE; +#ifdef IFF_RUNNING if (!(ifr.ifr_flags & IFF_RUNNING)) goto END_FALSE; +#endif if (if_up_strictness.get(*state) == IFUP_LINK) goto END_TRUE; @@ -519,7 +525,7 @@ int interface_up(struct text_object *obj) perror("SIOCGIFADDR"); goto END_FALSE; } - if (((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_addr))->sin_addr.s_addr) + if (((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr) goto END_TRUE; END_FALSE: