/*
 *libproc
 *
 *A library interface for finding process information from /proc.
 *This is also an interface into various things which haven't yet been integrated into sysfs,
 *  as appropriate.

 Copyright (C) 2004  Joseph Pingenot
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version  2.1  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; if not, write  to  the  Free Software
 Foundation,  Inc.,  59  Temple  Place,  Suite 330, Boston, MA 02111-1307  USA

*/

#include "acpi.h"

#ifndef LIBPROC_H_DKAFH4U3AG9Q0JRIOEQAIJ
#define LIBPROC_H_DKAFH4U3AG9Q0JRIOEQAIJ

#define LIBPROC_ERRLEN 1024

/*Get loadavg information*/
struct libproc_loadavg {
  float one;
  float two;
  float three;
  long unsigned int running;
  long unsigned int total;
  long unsigned int lastproc;
};
struct libproc_loadavg *libproc_getloadavg();
void libproc_destroy_loadavg(struct libproc_loadavg *la);



/*multistring list.  This is a linked list of multiple strings.
 *The fields are self-explanatory.
 *NOTE: the buffer must be freed before the struct can be freed!!
 *  OTHERWISE YOU GET A MEMORY LEAK
 */
struct libproc_list_multistring {
  long unsigned int len;
  char *buffer;
  struct libproc_list_multistring *next;
};

struct libproc_list_environ {
  long unsigned int varnamelen;
  char *varname;
  long unsigned int varcontentlen;
  char *varcontent;
  struct libproc_list_environ *next;
};

struct libproc_list_fds {
  unsigned int fd;
  unsigned long int filelen;
  char *file;
  struct libproc_list_fds *next;
};

struct libproc_list_mmap {
  unsigned long int start;
  unsigned long int stop;
  unsigned int mode;
  struct libproc_list_mmap *next;
};

struct libproc_list_mount {
  unsigned long int devlen;
  char *dev;
  unsigned long int mountpointlen;
  char *mountpoint;
  unsigned long int fslen;
  char *fs;
  unsigned int flags;
  unsigned int dump;
  unsigned int pass;
};

struct libproc_stats {
  pid_t pid;
  char *tcomm;
  char state;
  pid_t ppid;
  pid_t pgid;
  pid_t sid;
  int tty_nr;
  int tty_pgrp;
};

struct libproc_mstats {
};

struct libproc_group {
  gid_t gid;
  struct libproc_grouplist *next;
}

struct libproc_status {
  char *name;
  char state;
  short int sleepavg;
  gid_t tgid;
  pid_t pid;
  pid_t ppid;
  pid_t tracer;
  uid_t uid0;
  uid_t uid1;
  uid_t uid2;
  uid_t uid3;
  gid_t gid0;
  gid_t gid1;
  gid_t gid2;
  gid_t gid3;
  int fdsize;
  struct libproc_group *groups;
  long int vmsize;
  long int vmlck;
  long int vmrss;
  long int vmdata;
  long int vmstck;
  long int vmexe;
  long int vmlib;
  long int threads;
  long int sigpnd;
  long int shdpnd;
  long int sigblk;
  long int sigign;
  long int sigcgt;
  long int capinh;
  long int capprm;
  long int capeff;
};

struct libproc_list_thread {
};

/*We provide all of the available process information at once, for the off chance that
 *  the process magically changes underneath us.  IF we were to just let it go,
 *  the process might change between invocations.
 *NOTE: you must free the strings here, or you'll have a memory leak!
 */
struct libproc_process {
  /*The command line for the process*/
  struct libproc_list_multistring *cmdline;
  /*Current Working Directory*/
  unsigned long int cwdlen;
  char *cwd;
  /*Process's environment*/
  struct libproc_list_environ *environ;
  /*File descriptors it has open*/
  struct libproc_list_fds *fds;
  /*Memory map*/
  struct libproc_list_mmap *mmap;
  /*Mounts*/
  struct libproc_list_mount *mounts;
  /*Root directory*/
  unsigned long int rootlen;
  char *root;
  /*Stats*/
  struct libproc_stats stats;
  /*M Stats*/
  struct libproc_mstats mstats;
  /*Status*/
  struct libproc_status status;
  /*Threads*/
  struct libproc_list_thread *threads;
  /*wchan*/
  unsigned long int wchanlen;
  char wchan;
  /*These can be linked together to get an atomic state*/
  struct libproc_process *next;
};


#endif //LIBPROC_H_DKAFH4U3AG9Q0JRIOEQAIJ

