Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / svc_col.cpp
blob386a463ab0a5781dd26478f648b3a1e1875d813f
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "svc_col.h"
23 * SERVICE-VIEW COLUMNS _______________________________________________________
27 void Services_SetDefaultView (LPVIEWINFO lpvi)
29 lpvi->lvsView = FLS_VIEW_LIST;
30 lpvi->nColsAvail = nSERVICECOLUMNS;
32 for (size_t iCol = 0; iCol < nSERVICECOLUMNS; ++iCol)
34 lpvi->cxColumns[ iCol ] = SERVICECOLUMNS[ iCol ].cxWidth;
35 lpvi->idsColumns[ iCol ] = SERVICECOLUMNS[ iCol ].idsColumn;
38 lpvi->iSort = svccolNAME;
40 lpvi->nColsShown = 3;
41 lpvi->aColumns[0] = (int)svccolNAME;
42 lpvi->aColumns[1] = (int)svccolSTATUS;
43 lpvi->aColumns[2] = (int)svccolDATE_STARTSTOP;
48 * ROUTINES ___________________________________________________________________
52 size_t Services_GetAlertCount (LPSERVICE lpService)
54 return Alert_GetCount (lpService->GetIdentifier());
58 LPTSTR Services_GetColumnText (LPIDENT lpi, SERVICECOLUMN svccol, BOOL fShowServerName)
60 static TCHAR aszBuffer[ nSERVICECOLUMNS ][ cchRESOURCE ];
61 static size_t iBufferNext = 0;
62 LPTSTR pszBuffer = aszBuffer[ iBufferNext++ ];
63 if (iBufferNext == nSERVICECOLUMNS)
64 iBufferNext = 0;
65 *pszBuffer = TEXT('\0');
67 LPSERVICESTATUS lpss = NULL;
68 LPSERVICE_PREF lpsp;
69 if ((lpsp = (LPSERVICE_PREF)lpi->GetUserParam()) != NULL)
70 lpss = &lpsp->ssLast;
72 switch (svccol)
74 case svccolNAME:
75 if (!fShowServerName)
76 lpi->GetServiceName (pszBuffer);
77 else
79 TCHAR szNameSvr[ cchNAME ];
80 TCHAR szNameSvc[ cchNAME ];
81 lpi->GetServerName (szNameSvr);
82 lpi->GetServiceName (szNameSvc);
83 LPTSTR pszName = FormatString (IDS_SERVER_SERVICE, TEXT("%s%s"), szNameSvr, szNameSvc);
84 lstrcpy (pszBuffer, pszName);
85 FreeString (pszName);
87 break;
89 case svccolTYPE:
90 if (lpss)
92 if (lpss->type == SERVICETYPE_SIMPLE)
93 GetString (pszBuffer, IDS_SERVICETYPE_SIMPLE);
94 else if (lpss->type == SERVICETYPE_FS)
95 GetString (pszBuffer, IDS_SERVICETYPE_FS);
96 else
97 GetString (pszBuffer, IDS_SERVICETYPE_CRON);
99 break;
101 case svccolPARAMS:
102 if (lpss)
104 lstrncpy (pszBuffer, lpss->szParams, cchRESOURCE-1);
105 pszBuffer[ cchRESOURCE-1 ] = TEXT('\0');
107 for (LPTSTR pch = pszBuffer; *pch; ++pch)
109 if (*pch == TEXT('\r') || *pch == TEXT('\t') || *pch == TEXT('\n'))
110 *pch = TEXT(' ');
113 break;
115 case svccolNOTIFIER:
116 if (lpss)
118 lstrncpy (pszBuffer, lpss->szNotifier, cchRESOURCE-1);
119 pszBuffer[ cchRESOURCE-1 ] = TEXT('\0');
121 for (LPTSTR pch = pszBuffer; *pch; ++pch)
123 if (*pch == TEXT('\r') || *pch == TEXT('\t') || *pch == TEXT('\n'))
124 *pch = TEXT(' ');
127 break;
129 case svccolSTATUS:
130 if (lpss)
132 if (lpss->state == SERVICESTATE_RUNNING)
133 GetString (pszBuffer, IDS_SERVICESTATE_RUNNING);
134 else if (lpss->state == SERVICESTATE_STOPPING)
135 GetString (pszBuffer, IDS_SERVICESTATE_STOPPING);
136 else if (lpss->state == SERVICESTATE_STARTING)
137 GetString (pszBuffer, IDS_SERVICESTATE_STARTING);
138 else
139 GetString (pszBuffer, IDS_SERVICESTATE_STOPPED);
141 break;
143 case svccolDATE_START:
144 if (lpss)
146 if (!FormatTime (pszBuffer, TEXT("%s"), &lpss->timeLastStart))
147 pszBuffer[0] = TEXT('\0');
149 break;
151 case svccolDATE_STOP:
152 if (lpss)
154 if (!FormatTime (pszBuffer, TEXT("%s"), &lpss->timeLastStop))
155 pszBuffer[0] = TEXT('\0');
157 break;
159 case svccolDATE_STARTSTOP:
160 if (lpss)
162 LPSYSTEMTIME pst;
163 int ids;
164 if ((lpss->state == SERVICESTATE_RUNNING) || (lpss->state == SERVICESTATE_STARTING))
166 ids = IDS_SERVICE_STARTDATE;
167 pst = &lpss->timeLastStart;
169 else
171 ids = IDS_SERVICE_STOPDATE;
172 pst = &lpss->timeLastStop;
175 TCHAR szDate[ cchRESOURCE ];
176 if (FormatTime (szDate, TEXT("%s"), pst))
178 LPTSTR psz = FormatString (ids, TEXT("%s"), szDate);
179 lstrcpy (pszBuffer, psz);
180 FreeString (psz);
183 break;
185 case svccolDATE_FAILED:
186 if (lpss)
188 if (!FormatTime (pszBuffer, TEXT("%s"), &lpss->timeLastFail))
189 pszBuffer[0] = TEXT('\0');
191 break;
193 case svccolLASTERROR:
194 if (lpss)
196 LPTSTR psz = FormatString (IDS_SERVICE_LASTERROR, TEXT("%ld"), lpss->dwErrLast);
197 lstrcpy (pszBuffer, psz);
198 FreeString (psz);
200 break;
203 return pszBuffer;