Added missing files for profile patch

This commit is contained in:
Jaroslav Kysela 2004-05-16 13:37:31 +00:00
parent f0db78cea5
commit d552f0ca37
4 changed files with 1436 additions and 0 deletions

View file

@ -0,0 +1,101 @@
Profiles management as part of alsa
2004-05-16 Dirk Kalis <dirk.kalis@t-online.de>
General
=======
Profiles management can be used from all applications like mixers or hardware control programs.
It uses always alsactl and if directorys for the profiles file doesn't exists - mkdir.
profiles file means the file in which the profiles will be stored.
For other application the following files are needed:
profiles.h - header file with the exported functions
profiles.c - profiles implementation
new_process.c - used to start external programs (alsactl and mkdir)
strstr_icase_blank.c - string search function with ignoring case sensitivity, number of blanks, empty and
comment lines (first non blank character '#')
Profile numbers beginning with number 1 not 0 !
Introduction
============
Profiles management stores and restores alsactl settings in a profiles file.
Every card is stored in the profiles and every card profile can have a profile name.
The profiles file has the following structure:
[ profile <profile number> ]
< Card <card number> >
{ /<profile name/ }
***************************
*** alsactl settings ***
***************************
< /CARD <card number> >
-----next card or next profile or end of file-----
The header for profile name and card footer are optional.
The functions in profile.c write always a card footer.
DO NOT EDIT THIS FILE MANUALLY BECAUSE EVERY WRITE ACCESS MAKE A REORGANIZATION AND COMMENTS NOT WRITTEN IN
THE ALSACTL SECTION WILL BE REMOVED! ALSO THE STRUCTURE OF THE FILE WILL BE MODIFIED!
With the environment variables ALACTL_PROG and MKDIR_PROG can the compiled defaults for this
programs be overwritten.
e.g.:
export ALSACTL_PROG=<path and name from alsactl>;export MKDIR_PROG=<path and name from mkdir>;<mixer program with profiles management>
This pathes must not be a link !
The profiles file name and path can explicit given.
If is not given (by value NULL) two defined defaults will be used.
Two variables can be set in the profiles header file for the default profiles file and for the system profiles file.
The default for DEFAULT_PROFILERC is ~/<program name>/profiles.conf.
The default for SYS_PROFILERC is /etc/<program name>/profiles.conf
The profiles management search for profiles file if no profiles file name is given.
Search order for restore:
<given profiles file> if not -> <DEFAULT_PROFILERC> if doesn't exists -> <SYS_PROFILERC>
Search order for save:
<given profiles file> if not -> <DEFAULT_PROFILERC>
The SYS_PROFILERC can only be written as root by explicit given profiles file name or
you make a copy as root from one of the DEFAULT_PROFILERC.
This files must not be a link!
The delete_card function can be used to remove card profiles from profiles file if a card is removed from your pc.
Miscellaneous cards can have same profile names - thats no problem.
One card with equal profile names is also no problem if you use profile number for searching.
If you use profile name for searching you will allways get the least profile number with this profile name.
Profiles management in envy24control
====================================
In envy24control you can find a new map named "Profiles".
In this map you can store 8 profiles for every envy24 card.
You can change/give name by activating this profile and then click in the name entry.
You can only change the name for the active profile.
If all settings in the active profile are done you can save settings by clicking button "Save active profile".
Error messages will only displayed on stderr in the text window if you start envy24control from xterm.
To activate a profile click only the profile button.
You can start envy24control with given profiles file and a default profile. if a default profile is given
after initialisation of envy24control this profile will be activated.
Default profile can be given by profile number or profile name.
The accuracy of discrimination works in the following way:
- if the given default profile contains a letter -> profile name
- if the given default profile has a number outside the range [1 ... MAX_PROFILES] -> profile name
- the given default profile is interpreted as profile number.
Profile names should have at least one letter.
For "Delete card from profiles" and equal profile names read above.
One card with equal names is only a problem if you start envy24control with default profile name. You activate
allways the profile with the least profile number with this profile name.
Copyright
=========
Copyright Dirk Kalis<dirk.kalis@t-online.de>
This is free and can be distributed under GPL.

View file

@ -0,0 +1,86 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef MAX_PARAM
#define MAX_PARAM 10
#endif
/*
* start child process
*/
int new_process(char * const cmd_line[MAX_PARAM])
{
int proc_status;
pid_t pid;
pid_t w;
struct stat file_status;
/* memory for storage of function pointers from the signal handling routines */
void (*int_stat)();
void (*quit_stat)();
void (*usr2_stat)();
/*
* check command file
*/
/* search file */
if (stat(cmd_line[0], &file_status) < 0) {
fprintf(stderr, "Cannot find program '%s'.\n", cmd_line[0]);
fprintf(stderr, "You must specify path for '%s'.\n", cmd_line[0]);
return -errno;
}
proc_status = 0;
/* check file status and permissions */
if (file_status.st_mode & S_IFREG) {
if (!(file_status.st_mode & S_IXOTH)) {
if (!(file_status.st_mode & S_IXGRP)) {
if (!(file_status.st_mode & S_IXUSR)) {
proc_status = -EACCES;
} else if (file_status.st_uid != getuid()) {
proc_status = -EACCES;
}
} else if ((file_status.st_gid != getgid()) && (file_status.st_uid != getuid())) {
proc_status = -EACCES;
}
}
} else {
proc_status = -EACCES;
}
if (proc_status != 0) {
fprintf(stderr, "No permissions to execute program '%s'.\n", cmd_line[0]);
return proc_status;
}
if ( (pid = fork() ) == 0) {
execv(cmd_line[0], cmd_line);
}
/* for waiting ingnoring special interrupts */
int_stat = signal(SIGINT, SIG_IGN);
quit_stat = signal(SIGQUIT, SIG_IGN);
usr2_stat = signal(SIGUSR2, SIG_IGN);
/* waiting for the end of the child process */
while ( ( (w = wait(&proc_status)) != pid ) && (w != -1) )
;
if (w == -1) {
proc_status = -errno;
}
/* restore pointers from signal handling routines */
signal(SIGINT, int_stat);
signal(SIGQUIT, quit_stat);
signal(SIGUSR2, usr2_stat);
return proc_status;
}

1165
envy24control/profiles.c Normal file

File diff suppressed because it is too large Load diff

84
envy24control/profiles.h Normal file
View file

@ -0,0 +1,84 @@
#ifndef __PROFILES_H__
#define __PROFILES_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include <errno.h>
#include <assert.h>
#include <time.h>
#ifndef PROGRAM_NAME
#define PROGRAM_NAME "envy24control"
#endif
#ifndef MAX_PROFILES
#define MAX_PROFILES 4
#endif
#ifndef MAX_PROFILE_NAME_LENGTH
#define MAX_PROFILE_NAME_LENGTH 20
#endif
#ifndef DEFAULT_PROFILERC
#define DEFAULT_PROFILERC "~/"PROGRAM_NAME"/profiles.conf"
#endif
#ifndef SYS_PROFILERC
#define SYS_PROFILERC "/etc/"PROGRAM_NAME"/profiles.conf"
#endif
#define PROFILE_NAME_FIELD_LENGTH MAX_PROFILE_NAME_LENGTH + 1
#define PROFILE_HEADER_TEMPL "[ Profile # ]"
#define CARD_HEADER_TEMPL "< Card # >"
#define CARD_FOOTER_TEMPL "< /CARD # >"
#define PROFILE_NAME_TEMPL "{ /$/ }"
#define PLACE_HOLDER_NUM '#'
#define PLACE_HOLDER_STR '$'
/* max 32k for every profile */
#define MAX_PROFILE_SIZE 32768
#define MAX_SEARCH_FIELD_LENGTH 1024
#define MAX_FILE_NAME_LENGTH 1024
#define MAX_NUM_STR_LENGTH 10
#define TOKEN_SEP "|"
#define SEP_CHAR ' '
#ifndef NOTFOUND
#define NOTFOUND -1
#endif
#define ALSACTL_OP_STORE "store"
#define ALSACTL_OP_RESTORE "restore"
#define DIR_CREA_MODE "0755" // this must be a string
#define FILE_CREA_MODE 0644 // this must be a octal number
/* max count of parameters for new_process
* !first parameter will be the name of the external programm
* - last parameter will be NULL
*/
#define MAX_PARAM 10
/* the place from mkdir */
#ifndef MKDIR
#define MKDIR "/bin/mkdir"
#endif
/* the place from alsactl */
#ifndef ALSACTL
#define ALSACTL "/usr/sbin/alsactl"
#endif
#ifndef __PROFILES_C__
extern int save_restore(const char * const operation, const int profile_number, const int card_number, char * cfgfile, const char * const profile_name);
extern char *get_profile_name(const int profile_number, const int card_number, char * cfgfile);
extern int get_profile_number(const char * const profile_name, const int card_number, char * cfgfile);
extern int delete_card(const int card_number, char * const cfgfile);
#endif
#endif /* __PROFILES_H__ */