1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxSingleInstanceChecker documentation
4 %% Author: Vadim Zeitlin
8 %% Copyright: (c) 2001 Vadim Zeitlin
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxSingleInstanceChecker
}}\label{wxsingleinstancechecker
}
14 wxSingleInstanceChecker class allows to check that only a single instance of a
15 program is running. To do it, you should create an object of this class. As
16 long as this object is alive, calls to
17 \helpref{IsAnotherRunning()
}{wxsingleinstancecheckerisanotherrunning
} from
18 other processes will return
{\tt true
}.
20 As the object should have the life span as big as possible, it makes sense to
21 create it either as a global or in
\helpref{wxApp::OnInit
}{wxapponinit
}. For
27 const wxString name = wxString::Format("MyApp-
%s", wxGetUserId().c_str());
28 m_checker = new wxSingleInstanceChecker(name);
29 if ( m_checker->IsAnotherRunning() )
31 wxLogError(_("Another program instance is already running, aborting."));
36 ... more initializations ...
49 Note using
\helpref{wxGetUserId()
}{wxgetuserid
} to construct the name: this
50 allows different user to run the application concurrently which is usually the
51 intended goal. If you don't use the user name in the wxSingleInstanceChecker
52 name, only one user would be able to run the application at a time.
54 This class is implemented for Win32 and Unix platforms (supporting
{\tt fcntl()
}
55 system call, but almost all of modern Unix systems do) only.
57 \wxheading{Derived from
}
61 \wxheading{Include files
}
65 \latexignore{\rtfignore{\wxheading{Members
}}}
67 \membersection{wxSingleInstanceChecker::wxSingleInstanceChecker
}\label{wxsingleinstancecheckerctor
}
69 \func{}{wxSingleInstanceChecker
}{\void}
71 Default ctor, use
\helpref{Create()
}{wxsingleinstancecheckercreate
} after it.
73 \membersection{wxSingleInstanceChecker::wxSingleInstanceChecker
}\label{wxsingleinstancecheckerwxsingleinstancechecker
}
75 \func{}{wxSingleInstanceChecker
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{path = wxEmptyString
}}
77 Like
\helpref{Create()
}{wxsingleinstancecheckercreate
} but without
80 \membersection{wxSingleInstanceChecker::Create
}\label{wxsingleinstancecheckercreate
}
82 \func{bool
}{Create
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{path = wxEmptyString
}}
84 Initialize the object if it had been created using the default constructor.
85 Note that you can't call Create() more than once, so calling it if the
86 \helpref{non default ctor
}{wxsingleinstancecheckerwxsingleinstancechecker
}
87 had been used is an error.
89 \wxheading{Parameters
}
91 \docparam{name
}{must be given and be as unique as possible. It is used as the
92 mutex name under Win32 and the lock file name under Unix.
93 \helpref{GetAppName()
}{wxappgetappname
} and
\helpref{wxGetUserId()
}{wxgetuserid
}
94 are commonly used to construct this parameter.
}
96 \docparam{path
}{is optional and is ignored under Win32 and used as the directory to
97 create the lock file in under Unix (default is
98 \helpref{wxGetHomeDir()
}{wxgethomedir
})
}
100 \wxheading{Return value
}
102 Returns
{\tt false
} if initialization failed, it doesn't mean that another
103 instance is running - use
104 \helpref{IsAnotherRunning()
}{wxsingleinstancecheckerisanotherrunning
} to check
109 One of possible reasons while Create may fail on Unix is that the lock file
110 used for checking already exists but was not created by the user.
111 Therefore applications shouldn't treat failure of this function as fatal
112 condition, because doing so would open them to the possibility of a Denial of
113 Service attack. Instead, they should alert the user about the problem and
114 offer to continue execution without checking if another instance is running.
116 \membersection{wxSingleInstanceChecker::IsAnotherRunning
}\label{wxsingleinstancecheckerisanotherrunning
}
118 \constfunc{bool
}{IsAnotherRunning
}{\void}
120 Returns
{\tt true
} if another copy of this program is already running,
{\tt
123 \membersection{wxSingleInstanceChecker::
\destruct{wxSingleInstanceChecker
}}\label{wxsingleinstancecheckerdtor
}
125 \func{}{\destruct{wxSingleInstanceChecker
}}{\void}
127 Destructor frees the associated resources.
129 Note that it is not virtual, this class is not meant to be used polymorphically